python - Discord bot 回复其消息(python)
问题描述
if message.content.startswith('Привет'):
print('[command]: Задан вопрос3 ')
await message.channel.send('Привет ' + random.choice(list2) + '!')
if(messageAuthor == "Бот-Бобот#0869"):
return
我希望 discord bot 响应消息“Hello”,但响应中还包含单词“Hello”如何防止 bot 响应自身?
解决方案
您可以检查消息的作者是否是机器人本身。你可以这样做:
if not message.author.bot:
do_stuff()
else:
pass # author is bot, just ignore
试试这是否适合你
if message.author.bot:
return
# we will reach this point if and only if the author is NOT a bot
if message.content.startswith('Привет'):
print('[command]: Задан вопрос3 ')
await message.channel.send('Привет ' + random.choice(list2) + '!')
推荐阅读
- ffmpeg - FFMPEG 颜色到透明度
- c# - c#中的switch语句只能取整数值吗?
- javascript - 指数分布地形的细节
- php - 如何在 tpl 文件中调用 tcpdf 非静态方法
- python - scipy.optimize 矩阵约束问题
- django - 将域路径添加到 django html 模板
- javascript - 是否有任何更新来修复警告“ViewPager Android 已从 react-native 核心中提取”?
- keycloak - 向 JWT 添加声明的 Keycloak 协议映射器获取空指针异常
- laravel - 显示每个 b 表行的模式的按钮
- sql - 当我添加带有匕首 † 符号的 where 子句时,我的查询失败