Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

Discord.py ignore specified channel

I've got this code which logs deleted messages to a channel in my discord. However, I'd like to know how I could make it ignore one specified channel, which I do not wish for it to log deleted messages from. What would I need to edit into my code to do this? Thanks.

@bot.event
async def on_message_delete(message):
    embed=discord.Embed(title="{} deleted a message".format(message.author), description=" ", color=0x55246c)
    embed.add_field(name= message.content ,value="Message logging coded by ProfessorAdams.", inline=True)
    channel=bot.get_channel(CHANNEL_ID)
    await channel.send(embed=embed)

If you could let me know what to add to this code to make it ignore one channel, but work for every other channel, that would be amazing. Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can check if the deleted message channel id is equal to the channel id that you want it to ignore.

@bot.event
async def on_message_delete(message):
    if message.channel.id == <IGNORED_CHANNEL_ID>: #Enter the channel id that you want to ignore
        return
    embed=discord.Embed(title="{} deleted a message".format(message.author), description=" ", color=0x55246c)
    embed.add_field(name= message.content ,value="Message logging coded by ProfessorAdams.", inline=True)
    channel=bot.get_channel(CHANNEL_ID)
    await channel.send(embed=embed)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...