Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

python - How do I stop bots from triggering my bots commands?

I have a bot with some basic auto-responses. I have a separate bot with similar features and some shared auto-responses between the two bots. How do I block bots from triggering each other in discord.py?

My current code is this:

if discord.User.bot == True:
    return

That's placed inside my on_message() event, right at the start, after a check to see if the bot is the message triggering the event. This currently doesn't work. I'm new to the idea of importing stuff and using class systems so any help/clarification is useful!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're referring to the class itself, not the instance

async def on_message(message):
    if message.author.bot:
        return 

    # rest of the code here

Also this is only going to work on the on_message event, if you want it to work on commands you need to create a global check:

@bot.check # or client.check,
async def is_bot(ctx):
    return not ctx.author.bot

Reference:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...