Ákos Molnár
Ákos Molnár

Reputation: 55

Sending a user specified message into a specified channel

This bot is only going to be for personal use, so I don't need to make it customizable from discord itself. I was wondering if I can use ctx.send and channel.send somehow together if this makes sense. Here is my code to help you understand what I mean:

client = commands.Bot(command_prefix='!')

channel = client.get_channel(883389016819511296)

@client.command(name='say')
async def say(ctx, *, content):
  await ctx.send(content) # here I want to send it to the channel I already defined

channel.send would be an option, but I also want to send the message, so if I am right I need to use ctx.

Upvotes: 0

Views: 39

Answers (1)

newbiedpycoder
newbiedpycoder

Reputation: 69

No, you need to use channel.send as you are sending the content to the specified channel. If you use ctx.send it will just send in the same channel as the command was executed in. And theres an easier way to do this if you wanna see and example i have one here

@client.command() async def say(ctx, channel: discord.TextChannel, *, message: str): await channel.send(message)

That is an easier way and you can "#" the text channel so for example if you want to send a message in general for your bot it would be: !say #general hello However if you only wish to do that and not use my example then you should do it like this:

@client.command(name='say') async def say(ctx, *, content): channel = client.get_channel(883389016819511296) await channel.send(content)

Upvotes: 1

Related Questions