【发布时间】:2020-08-16 15:32:45
【问题描述】:
我对制作不和谐机器人相当陌生,我正在尝试制作一个基本的测试命令,你说(前缀)测试 abc,机器人也说 abc。我没有收到任何错误,但是当我输入 r!test abc 时,什么也没有发生。我在终端也一无所获。
这是我的代码。
import discord
from dotenv import load_dotenv
from discord.ext import commands
load_dotenv()
GUILD = os.getenv('DISCORD_GUILD') # Same thing but gets the server name
client = discord.Client()
bot = commands.Bot(command_prefix='r!')
TOKEN = 'TOKENGOESHERE'
on = "I'm up and running!"
print("Booting up...")
channel = client.get_channel(703869904264101969)
@client.event # idk what this means but you have to do it
async def on_ready(): # when the bot is ready
for guild in client.guilds:
if guild.name == GUILD:
break
print(f'{client.user} has connected to Discord! They have connected to the following server: ' #client.user is just the bot name
f'{guild.name}(id: {guild.id})' # guild.name is just the server name
)
channel2 = client.get_channel(channelidishere)
await channel2.send(on)
#everything works up until I get to here, when I run the command, nothing happens, not even some output in the terminal.
@commands.command()
async def test(ctx):
await ctx.send("test")
client.run(TOKEN)
谢谢大家!
【问题讨论】:
-
机器人没有响应,这就是问题所在。我尝试了许多其他命令,其中机器人创建了一个频道,或者给某人一个角色,但这些也不起作用。即使是在终端中打印某些内容的基本命令也不起作用。
标签: python command discord.py