mirror of
https://github.com/opus-tango/minecraft-server-discord-bot.git
synced 2026-03-20 03:55:20 +00:00
41 lines
923 B
Python
41 lines
923 B
Python
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) |