【发布时间】:2021-01-17 02:28:46
【问题描述】:
当有人在频道中提到机器人时,我正在尝试这样做,机器人会向用户发送一条随机消息,但我尝试过的所有事情都没有奏效。 (discord.py)
channel = 797224597443051611
@bot.event
async def on_message(msg):
chat = bot.get_channel(797224597443051611)
if msg.channel.id != channel:
return
if bot.user.mentioned_in(msg):
await chat.send(msg.author.mention + " " + random.choice(text))
await bot.process_commands(msg)
这个方法我也试过了,还是不行。
channel = 797224597443051611
@bot.event
async def on_message(msg):
if msg.channel.id != channel:
return
if bot.user.mentioned_in(msg):
await msg.send(msg.author.mention + " " + random.choice(text))
await bot.process_commands(msg)
【问题讨论】:
-
有什么错误吗?
-
不,一切正常,但机器人没有反应。
-
第一个代码应该可以正常工作,除非
text变量没有问题。 -
你在哪里声明
channel = 797224597443051611?尝试在on_message函数中这样做。 -
由于某种原因它不起作用,我知道它应该,我尝试了使用通道的方法,但它也不起作用。
标签: python pycharm discord.py