Issue
Whenever a message is deleted, I want that message to be sent into another channel sort of like a log. Basically whenever the message is deleted within a certain channel, I want that sniped/deleted message to be sent into another channel.
Example: If a message gets deleted in the channel X, I want the message content to go to channel Y.
Code
import discord
from discord.ext import commands
from tokens import token, CHANNEL_ID
client = commands.Bot(command_prefix='!')
client.sniped_message = None
@client.event
async def on_ready():
print("Your bot is ready.")
@client.event
async def on_message(message):
if message.channel.id == CHANNEL_ID and message.author != client.user:
print(f'Fetched message: {message}')
client.sniped_message = message
@client.command()
async def snipe(ctx):
if ctx.channel.id != CHANNEL_ID:
return
if client.sniped_message is None:
await ctx.channel.send("Couldn't find a message to fetch!")
return
message = client.sniped_message
embed = discord.Embed(
description=message.content,
color=discord.Color.purple(),
timestamp=message.created_at
)
embed.set_author(
name=f"{message.author.name}#{message.author.discriminator}",
icon_url=message.author.avatar_url
)
embed.set_footer(text=f"Message sent in: #{message.channel.name}")
await ctx.channel.send(embed=embed)
# assume I would be sending the embed to another channel but not sure how to tackle that
client.run(token)
Help is very appreciated! PS: I am very new to Python and it is very different from JS...
Solution
Get the Channel Y like this first:
channely = client.get_channel(channel_id)
Then you can do
await channely.send(client.sniped_message)
Answered By - DriftAsimov Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.