Home > other >  Make Discord.py Bot Only Work In Specific Channels
Make Discord.py Bot Only Work In Specific Channels

Time:10-31

I was making a bot for my friend using discord.py and I wanted to make it so that it would only work in channel which include the word ticket, made by another bot named Ticket Toll

How can I do so?

CodePudding user response:

Only give the bot access to read channels where you want it to work.

CodePudding user response:

Relevant docs on text channels

Unfortunately, Discord's API does not keep track of who created the channel (which is why there's no such thing as channel.author).

One solution would be to have Ticket Toll create channels in a category, and only give your bot permissions to view this category.

However, you can easily have the bot ignore messages if the channel doesn't have "ticket" in the name, by checking channel.name. Here's an example with the on_message event:

@client.event
async def on_message(message):
    if 'ticket' not in message.channel.name: return
    # stuff to execute if message was sent in a channel with ticket in its name

Or as a command:

@client.command()
async def something(ctx, arg):
    if "ticket" not in ctx.message.channel.name: return
    # stuff to execute if the command was sent in a channel with ticket in its name
  • Related