mirror of
https://github.com/opus-tango/minecraft-server-discord-bot.git
synced 2026-03-20 03:55:20 +00:00
pass discord chat to mc
This commit is contained in:
5
bot.py
5
bot.py
@@ -39,11 +39,12 @@ async def on_message(message):
|
|||||||
print(f'Message from {message.author}: {message.content}')
|
print(f'Message from {message.author}: {message.content}')
|
||||||
if message.author == bot.user:
|
if message.author == bot.user:
|
||||||
return
|
return
|
||||||
if message.channel.name == chat_channel:
|
if message.channel.name == chat_channel and not message.content.startswith(command_prefix):
|
||||||
if not active_server:
|
if not active_server:
|
||||||
await ("No server is currently active.")
|
await ("No server is currently active.")
|
||||||
return
|
return
|
||||||
await send_message(message)
|
await send_message(message)
|
||||||
|
if message.channel.name == command_channel and message.content.startswith(command_prefix):
|
||||||
await bot.process_commands(message)
|
await bot.process_commands(message)
|
||||||
|
|
||||||
async def send_message(message):
|
async def send_message(message):
|
||||||
@@ -51,7 +52,7 @@ async def send_message(message):
|
|||||||
await message.channel.send("No server is currently active.")
|
await message.channel.send("No server is currently active.")
|
||||||
return
|
return
|
||||||
minecraft_message = "[" + message.author.name + "] " + message.content
|
minecraft_message = "[" + message.author.name + "] " + message.content
|
||||||
process = subprocess.Popen(f"screen -S {active_server} -p 0 -X stuff '{minecraft_message}'", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
process = subprocess.Popen(f"screen -S {active_server} -p 0 -X stuff '{minecraft_message}\n'", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
stdout, stderr = process.communicate()
|
stdout, stderr = process.communicate()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user