首页 > 解决方案 > 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 响应自身?

标签: pythondiscordbots

解决方案


您可以检查消息的作者是否是机器人本身。你可以这样做:

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) + '!')

推荐阅读