Blazer Progs
Blazer Progs

Reputation: 1

Please help me with the code to send a message to the channel

I want the code to work what I wrote-test2 #chat and the bot sent a message there, but my code doesn't work. Please help me with the code and tell me where I made the mistake. I will be grateful! My code:

@client.command()
async def test2(ctx, name):
    chans = get(ctx.guild.channels, name = name)
    
    e = discord.Embed(title = f'hello')
    await chans.send(embed = e)

Upvotes: 0

Views: 45

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15728

If you print the name argument, you'll get something like this <#771335478372204575>, it's not a channel name, neither an ID

Top fix it you can use converters

@client.command()
async def test2(ctx, channel: discord.TextChannel):
    e = discord.Embed(title='hello')
    await channel.send(embed=e)

Upvotes: 2

Related Questions