python-3.x - 如何让机器人忽略 discord.py 中的某些频道?
问题描述
我正在尝试制作一个机器人,当他们说出某些关键字时将成员重定向到某个频道,但我不希望机器人告诉他们如果他们已经在 #commands 中,则进入 #commands。如何让机器人忽略#commands 中的所有消息?
解决方案
只需在 on_message 事件中添加一个检查即可返回是否message.channel.id
等于#commands 的 id。
@client.event
async def on_message(message):
#Ignore messages sent in channel with id 1234567890 (#commands channel)
if message.channel.id == 1234567890:
return
#Ignore messages sent by the bot
if message.author == client.user:
return
推荐阅读
- django - 获取 Django 表单字段的人类可读值
- powerbi - 在 Power BI 中以工作区管理员身份重新发布 pbix 报表时,您无权发布到此工作区
- android - 如何结合 API 12 斜线屏幕获得 Firebase 结果?
- git - 发送拉取请求后从远程主分支拉取
- c# - SelectBox 不显示从 ViewData 字典传输的数据
- jwt - 来自外部发行者的 .NET 5 Web API Jwt 令牌
- logic - VHDL 中的多输入案例语句
- html - Django要求填写不需要的表格
- c - g_slist_copy_deep 返回分段错误
- dictionary - In Here Map - 如何搜索地址列表