微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将被狙击的消息发送到另一个频道? 不和谐.py 首先像这样获取频道 Y:

如何解决如何将被狙击的消息发送到另一个频道? 不和谐.py 首先像这样获取频道 Y:

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

示例:如果消息在频道 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 非常不同...

解决方法

首先像这样获取频道 Y:

channely = client.get_channel(channel_id)

然后你就可以了

await channely.send(client.sniped_message)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。