Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

discord.py send bot message then pin (rewrite)

So I'm making a guess the number bot. I'd like the bot to send when the number is guessed and then pin the message of what the bot sent. How can I do this?

@client.event
async def on_message(message):
    if message.content == str(number) and message.channel.id == 555146955815256065:
        author = message.author.id
        await message.channel.send("Congratulations <@" + str(author) + ">! You guessed the number, `" + str(number) + "`!")
        await message.pin()

I've done this and this will pin the message the user sent, not the bots message,

Any help is appreciated, thanks!

like image 812
Computerpro Avatar asked Dec 29 '25 11:12

Computerpro


1 Answers

You have to define the message sent by the bot (For example here as botmsg) and pin this. Otherwise it pins the message defined in on_message(message) what is the message on what the bot reacts.

Also I overworked the message itself so it is much easier to mention the user and insert the number (which you could also do as an integer but string also works).

@client.event
async def on_message(message):
    if message.content == str(number) and message.channel.id == 555146955815256065:
        botmsg = await message.channel.send(f"Congratulations {message.author.mention}! You guessed the number, `{number}`!")
        await botmsg.pin()
like image 56
FlexGames Avatar answered Dec 31 '25 02:12

FlexGames



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!