Discord 机器人在 Python 代码中未被识别为机器人
Discord Bots are not recognized as Bots in Python code
我正在编写一个 discordbot 机器人,该功能 user.bot 无法正常工作
@client.event
async on_reaction_add(reaction, user):
if not user.bot:
await client.wait_until_ready()
try:
channel = client.get_channel(welcome_channel_id)
try:
await channel.send(message)
await reaction.remove(user)
except Exception as e
raise e
except Exception as e
raise e
接受 if 语句一切正常,我创建了一条带有机器人反应的消息,但机器人反应被删除了。
我正在使用 Python 3.8。如果您需要任何额外信息,请告诉我。
你的 try
代码块每次都在执行 if 语句后执行。
我假设它应该只在 if
语句的计算结果为 true
:
时执行
if not user.bot:
await client.wait_until_ready()
try:
channel = client.get_channel(welcome_channel_id)
await channel.send(message)
await reaction.remove(user)
except Exception as e
raise e
但是
raise e
否定了使用 try/catch 块的全部意义 - 它没有任何效果。
以上代码等同于
if not user.bot:
await client.wait_until_ready()
channel = client.get_channel(welcome_channel_id)
await channel.send(message)
await reaction.remove(user)
我正在编写一个 discordbot 机器人,该功能 user.bot 无法正常工作
@client.event
async on_reaction_add(reaction, user):
if not user.bot:
await client.wait_until_ready()
try:
channel = client.get_channel(welcome_channel_id)
try:
await channel.send(message)
await reaction.remove(user)
except Exception as e
raise e
except Exception as e
raise e
接受 if 语句一切正常,我创建了一条带有机器人反应的消息,但机器人反应被删除了。 我正在使用 Python 3.8。如果您需要任何额外信息,请告诉我。
你的 try
代码块每次都在执行 if 语句后执行。
我假设它应该只在 if
语句的计算结果为 true
:
if not user.bot:
await client.wait_until_ready()
try:
channel = client.get_channel(welcome_channel_id)
await channel.send(message)
await reaction.remove(user)
except Exception as e
raise e
但是
raise e
否定了使用 try/catch 块的全部意义 - 它没有任何效果。
以上代码等同于
if not user.bot:
await client.wait_until_ready()
channel = client.get_channel(welcome_channel_id)
await channel.send(message)
await reaction.remove(user)