Discord py 命令随机工作并且不工作
Discord py command randomly works and doesnt
我有一个 discord 命令,当用“-meme”触发时,它将等待用户上传图片,然后将图片 URL 发回给他们
@client.event
async def on_message(message):
if message.content.startswith('-meme'):
channel = message.channel
author = message.author
await channel.send('Upload a image')
def check(m):
return m.author == m.author and m.channel == channel
msg = await client.wait_for('message', check=check)
await channel.send(msg.attachments[0].url)
有时会成功,机器人会发回图像 url,有时机器人不会 return 任何东西并给出此错误,"IndexError: list index out of range"
老实说,我不知道该尝试什么,也不知道为什么它有时有效,有时却无效,所以感谢您的帮助
在您的 check
中,尝试为邮件中的附件数量添加一个:
def check(m):
return ... and len(m.attachments) != 0
发生错误是因为检查正在对作者在频道中发送的 any 消息评估为 True
在那条消息之后,是否有附件。
但是如果用户还上传了附件,添加额外条件只会让检查评估为 True
。
参考文献:
我有一个 discord 命令,当用“-meme”触发时,它将等待用户上传图片,然后将图片 URL 发回给他们
@client.event
async def on_message(message):
if message.content.startswith('-meme'):
channel = message.channel
author = message.author
await channel.send('Upload a image')
def check(m):
return m.author == m.author and m.channel == channel
msg = await client.wait_for('message', check=check)
await channel.send(msg.attachments[0].url)
有时会成功,机器人会发回图像 url,有时机器人不会 return 任何东西并给出此错误,"IndexError: list index out of range" 老实说,我不知道该尝试什么,也不知道为什么它有时有效,有时却无效,所以感谢您的帮助
在您的 check
中,尝试为邮件中的附件数量添加一个:
def check(m):
return ... and len(m.attachments) != 0
发生错误是因为检查正在对作者在频道中发送的 any 消息评估为 True
在那条消息之后,是否有附件。
但是如果用户还上传了附件,添加额外条件只会让检查评估为 True
。
参考文献: