简体   繁体   English

Discord.py - 使用反应将嵌入的消息发送到另一个频道

[英]Discord.py - Send embed messages to another channel using reactions

So I am trying to make embed messages be transferred between different text channels, there are three options.所以我试图让嵌入的消息在不同的文本频道之间传输,有三个选项。 'Fixed' - 'Not-A-Bug' - 'Not Fixed'. “已修复”-“非错误”-“未修复”。 The admin of the discord server will choose one of these three depending on the situation of a bug. Discord 服务器的管理员将根据错误的情况选择这三个中的一个。

The issue is that when I react to one of these emotes, it sends information about the message, like this: <Message id=735831838555242557 channel=<TextChannel id=733721953134837861 name='admin-bug' position=4 nsfw=False news=False category_id=733717942604398684> type=<MessageType.default: 0> author=<Member id=733720584831369236 name='ReefCraft' discriminator='3102' bot=True nick=None guild=<Guild id=733717942604398682 name="Pumbalo's server" shard_id=None chunked=True member_count=2>> flags=<MessageFlags value=0>>问题是,当我对这些表情之一做出反应时,它会发送有关消息的信息,如下所示: <Message id=735831838555242557 channel=<TextChannel id=733721953134837861 name='admin-bug' position=4 nsfw=False news=False category_id=733717942604398684> type=<MessageType.default: 0> author=<Member id=733720584831369236 name='ReefCraft' discriminator='3102' bot=True nick=None guild=<Guild id=733717942604398682 name="Pumbalo's server" shard_id=None chunked=True member_count=2>> flags=<MessageFlags value=0>>

I need it to send the embed, so instead of that^^ it should be like this:我需要它来发送嵌入,所以不是那个^^它应该是这样的:

在此处输入图片说明

Here is my python code:这是我的python代码:

import discord
from discord.ext import commands
import asyncio

TOKEN = '---'
bot = commands.Bot(command_prefix='!!')

emojis = ["\u2705", "\U0001F6AB", "\u274C"]

emojis2 = ["\u2705", "\u274C"]


@bot.event
async def on_ready():
    print('Bot is ready.')


@bot.command()
async def bug(ctx, desc=None, rep=None):
    user = ctx.author
    await ctx.author.send('```Please explain the bug```')
    responseDesc = await bot.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
    description = responseDesc.content
    await ctx.author.send('```Please provide pictures/videos of this bug```')
    responseRep = await bot.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
    replicate = responseRep.content
    embed = discord.Embed(title='Bug Report', color=0x00ff00)
    embed.add_field(name='Description', value=description, inline=False)
    embed.add_field(name='Replicate', value=replicate, inline=True)
    embed.add_field(name='Reported By', value=user, inline=True)
    adminBug = bot.get_channel(733721953134837861)
    message = await adminBug.send(embed=embed)
    # Add 3 reaction (different emojis) here
    for emoji in emojis:
        await message.add_reaction(emoji)

@bot.event
async def on_reaction_add(reaction, user):
    message = reaction.message
    emoji = reaction.emoji

    if user.bot:
        return

    if emoji == "\u2705":
        fixed_channel = bot.get_channel(733722567449509958)
        await fixed_channel.send(message)
    elif emoji == "\U0001F6AB":
        notBug = bot.get_channel(733722584801083502)
        await notBug.send(message)
    elif emoji == "\u274C":
        notFixed = bot.get_channel(733722600706146324)
        await notFixed.send(message)
    else:
        return

bot.run(TOKEN)

I have gotten some help before, but I never got it to work.我以前得到过一些帮助,但我从来没有让它起作用。

The problem is because you are sending the message object, and not its content.问题是因为您发送的是消息对象,而不是其内容。

What you want to be using is discord.Message.embeds to get the embed from the message.您想要使用的是discord.Message.embeds从消息中获取嵌入。

You can do this using the principles below:您可以使用以下原则执行此操作:

# your reaction message
reaction_message = reaction.message

#fetch the message
message = await reaction_message.channel.fetch_message(reaction_message.id)

# message.embeds is a list of embeds. Here we get get the first embed which is what you need
my_embed = message.embeds[0]

# now send the embed to the channel
await fixed_channel.send(embed=my_embed)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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