python - 如果为假,如何让我的程序跳过“on_message”函数(discord.py重写)
问题描述
我想让我的机器人能够在编写某个命令时标记成员,但我能够做到这一点的唯一方法是使用 on_message 命令,它似乎只是停止我的程序,无论是假还是真,即使它在何时激活真的
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('m-example'):
await message.channel.send('<' + '@' + '{}' .format(message.author.id) +'>' + ' example!')
解决方案
首先,您可以更轻松地提及某人,对于此示例,使用message.author.mention
,其次我不知道您有什么问题,但现在可能可行:
@client.event
async def on_message(message):
if message.author.id != bot.user.id:
if message.content.startswith('m-example'):
await message.channel.send(f"{message.author.mention} example!")
推荐阅读
- apache-flink - flink - 无法启动作业集群
- preact - 具有默认情况的 preact-router 未按预期工作
- c# - 无法将 SQL DATEDIFF 输出转换为 int - 输入字符串的格式不正确
- python - 在 python 3.x 中 pip 安装 pyodbc
- django - Django:从字典列表批量更新而不构建整个查询集
- google-bigquery - BigQuery - 修改预定查询
- ios - 在 UIApplication 上调用 -statusBar 或 -statusBarWindow 的应用程序
- sql-server - 执行存储过程返回语法错误,但运行查询有效
- android - TextInputLayout 样式
- java - 在滚动视图android中滚动时浮动动作按钮隐藏和显示?