Reputation: 129
Im kinda new to discord bot and python so I am running into a little trouble understanding where I am going wrong. Basically I want to get my bot to pin a message. I found a documentation for python code which says to use pin_message() so i have:
if "pinm()" == message.content.lower():
#to pin a message
message.channel.pin_message(messageID)
but i get the following error AttributeError: 'TextChannel' object has no attribute 'pin_message'
When I look at the Discord documentation it says PUT /channels/{channel.id}/pins/{message.id} I dont really understand how to translate this down to code so i have something like this:
if "pinm()" == message.content.lower():
#to pin a message
allPins = message.channel.pins(messageID)
but i get the error pins() takes 1 positional argument but 2 were given. The sources i am following are
https://discordapp.com/developers/docs/resources/channel#add-pinned-channel-message
https://discordpy.readthedocs.io/en/latest/api.html#message
Can anyone tell me where I am going wrong with this? :(
Upvotes: 0
Views: 7064
Reputation: 60994
Edit: You're actually using discord.py-rewrite, so you need to do
msg_to_pin = await message.channel.get_message(int(messageID))
await msg_to_pin.pin()
Original:
You need to use the Client.pin_message
, passing a Message
object (not the id). You frequently already have the message object, but otherwise you'll have to use Client.get_message
, which requires you to also know the channel the message is in.
msg_to_pin = await client.get_message(message.channel, messageID)
await client.pin_message(msg_to_pin)
Make sure your bot has the manage_messages
permission, or this will fail.
Upvotes: 1