我一直在尝试制作一个 Discord 机器人,它将侦听来自公会的 $start 命令,然后使用他们的 API 启动 Exaroton Minecraft 服务器。我一直在使用一些模板来让它只响应我所说的内容,但它仍然不起作用。我用来执行此操作的平台是 Replit。
import os
import random # Import the 'random' module
import discord
from discord import Intents
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
intents = Intents.default()
intents.messages = True
intents.guilds = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@client.event
async def on_message(message):
print(f"Message received: {message.content}")
if message.author == client.user:
return
brooklyn_99_quotes = [
'I\'m the human form of the 💯 emoji.',
'Bingpot!',
(
'Cool. Cool cool cool cool cool cool cool, '
'no doubt no doubt no doubt no doubt.'
),
]
if '99!' in message.content:
response = random.choice(brooklyn_99_quotes)
await message.channel.send(response)
async def start_bot():
await client.start(TOKEN)
async def main():
await start_bot()
if __name__ == '__main__':
discord.Client.run(client, TOKEN) # Run the client with the provided token
首先欢迎来到论坛。对我来说,你的不和谐机器人设置是在正确的轨道上。但是为了帮助您更多,您可以发送您在不工作时收到的错误日志吗?
无论如何,请确保您已安装 exaroton 模块 (pip install exaroton) 并在 .env 文件中提供您的 Discord 机器人令牌和 Exaroton API 令牌。另外,请确保您的机器人具有管理消息以及在其运行的通道中读/写的必要权限。