mirror of
https://github.com/opus-tango/minecraft-server-discord-bot.git
synced 2026-03-20 03:55:20 +00:00
create basic bot that handles commands
This commit is contained in:
41
bot.py
Normal file
41
bot.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import subprocess
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv('DISCORD_TOKEN')
|
||||
print(TOKEN)
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
bot = commands.Bot(command_prefix='!', intents=intents)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f'Logged in as {bot.user})')
|
||||
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
print(f'Message from {message.author}: {message.content}')
|
||||
await bot.process_commands(message)
|
||||
|
||||
@bot.command()
|
||||
async def mc(ctx, *args):
|
||||
command = ' '.join(args)
|
||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||
stdout, stderr = process.communicate()
|
||||
await ctx.send(stdout)
|
||||
|
||||
@bot.command()
|
||||
async def ping(ctx):
|
||||
await ctx.send('Pong!')
|
||||
|
||||
@bot.command()
|
||||
async def botstop(ctx):
|
||||
await bot.close()
|
||||
|
||||
|
||||
bot.run(TOKEN)
|
||||
Reference in New Issue
Block a user