栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

on_message()和@ bot.command问题

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

on_message()和@ bot.command问题

您必须放置

awaitbot.process_commands(message)
if
语句范围之外,
process_command
无论消息是否以“ /
lockdown”开头,都应运行。

@bot.eventasync def on_message(message):    if message.content.startswith('/lockdown'):       ...    await bot.process_commands(message)

顺便说一下,

@commands.has_role(...)
不适用于
on_message
。尽管没有任何错误(因为已经进行了检查),
has_role
但实际上并没有按您期望的那样工作。

@has_role
装饰器的替代方法是:

@bot.eventasync def on_message(message):    if message.channel.is_private or discord.utils.get(message.author.roles, name="Admin") is None:        return False    if message.content.startswith('/lockdown'):       ...    await bot.process_commands(message)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624581.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号