【发布时间】:2021-09-11 20:33:44
【问题描述】:
我正在使用 python (discord.py) 开发一个不和谐的机器人。 我试图为我的机器人发出聊天命令,但它没有回复,也没有错误。 我问了我的朋友,但他也不知道怎么做,有什么问题。 我的目标是让机器人做出回应,例如,如果我打招呼,它会回复 hello + me 提及。
这是我的代码:
async def chat(ctx):
await ctx.send("Chat mode ON")
hi = "hello", "hi", "hallo"
hgh = "how are you doing", "how are you doing?", "hoe gaat het?","how are you"
exit = "bye", "exit", "Bye","Exit"
invite = "invite", "can i get your invite link?"
msg = await bot.wait_for("message" )
if msg.content == hi:
await ctx.send("Hello " + ctx.message.author.mention)
if msg.content == hgh:
await ctx.send("Im doing as long as my script is running, how are you? " + ctx.message.author.mention)
if msg.content == exit:
await ctx.send("Bye, hope to see you again soon " + ctx.message.author.mention)
if msg.content == invite:
await ctx.send("This is my invite link: https://discord.com/oauth2/authorize?client_id=858775426490957845&permissions=8&scope=bot " + ctx.message.author.mention)```
If you know what is wrong with it and how to fix it please let me know, it would mean a lot to me.
【问题讨论】:
-
您必须使用
on_message(message)事件才能收听消息。 -
您正在将列表与字符串进行比较。请改用
in。 ->if msg.content in hi:等
标签: python discord command discord.py bots