如何将被狙击的消息发送到另一个频道? (不和谐.py)

时间:2021-05-10 02:39:52

标签: python discord message channels

每当删除一条消息时,我都希望将该消息发送到另一个频道,就像日志一样。基本上,每当在某个频道中删除消息时,我都希望将剪切/删除的消息发送到另一个频道。

示例:如果消息在频道 X 中被删除,我希望消息内容转到频道 Y。

代码

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)

非常感谢帮助! PS:我对 Python 很陌生,它与 JS 非常不同...

1 个答案:

答案 0 :(得分:1)

首先像这样获取频道 Y:

channely = client.get_channel(channel_id)

然后你就可以了

await channely.send(client.sniped_message)