简体   繁体   中英

How can i use discord py to pin an image from a user with a specific role in a specific channel

is it possible to have my bot pin an image uploaded to a set channel from users with admin roles?

this is what I've came up with so far

@bot.event
async def on_message(message):
    if message.author.id == "160319785840672768" and message.channel.id == "802523353964609566":
        return

    if message.content.startswith('pin'):
        await message.pin()```

Ok I figured out how to make it work

attachments is what was needed for the bot to pin the images channel.id and author.id are the conditions in needed for the bot to only pin when a specific user uploads an attachement to a specific channel

@bot.event
async def on_message(message):
    if message.author.id == bot.user:
        return

    if message.attachments and message.author.id == 160319785840672768 and message.channel.id == 802523353964609566 : # by adding this the bot only pins the messages from a specific user 
        await message.pin()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM