T8.0
T8.0

Reputation: 11

The bot don't send message in specific channel

I'm trying to make a partnership command and to do that I need the bot to send a message in a specific channel. This is the code:

bot.command()
async def force(ctx, *, message=None):
    channel = bot.get_channel(854633281589084221)
    await ctx.channel.send(message)

(Sorry for the bad translation)

In the line of code:

await ctx.channel.send(message)

If I put ctx before channel it works, but it sends the message in the channel in which the command was executed and the programme tells me that the local variable channel isn't used, while if I put it after it no longer tells me that channel isn't used but it does not work

Upvotes: 1

Views: 283

Answers (2)

aVeryBadCoder
aVeryBadCoder

Reputation: 23

(adding on to @TheSj)

When a command is ran, the bot already replies in that given channel.

If you want to make it so it can only reply in that channel, you can use discord permissions using roles and remove the role from each channel you don't want it in.

Hope this helps and have a great day.:)

Upvotes: 0

TheSj
TheSj

Reputation: 386

channel already has the value of the channel you want to send the message in.

So, you just need to run await channel.send(message) or await bot.get_channel(<id>).send(message) for your bot to work.

Upvotes: 1

Related Questions