问题描述
我正在尝试建立一个系统,当您对表情符号做出反应时,它将把该消息(取决于您对什么表情符号做出响应)发送到另一个文本通道,现在它将返回此消息而不是实际的消息:
<消息id = 733788372891467838 channel =< TextChannel id = 733721953134837861 name ='admin-bug'position = 1 nsfw = False news = False category_id = 733717942604398684> type =< MessageType.default:0> author =<会员id = 733720584831369236 name ='ReefCraft'discriminator ='3102'bot = True nick = None guild =<公会id = 733717942604398682 name = Pumbalo的服务器 shard_id =未分块= True member_count = 2>> flags =< MessageFlags value = 0>>
我试图在变量上使用 .content
,但它仍然无法正常工作,并且给了我错误:
discord.errors.HTTPException:400错误的请求(错误代码:50006):无法发送空消息
这是我的代码:
import discord
从discord.ext导入命令
import asyncio
TOKEN ='---'
bot =命令。Bot(command_prefix ='!!')
emojis = [ u2705, u0001F6AB, u274C]
@ bot.event
async def on_ready():
打印('Bot就绪。')
@ bot.command()
异步def bug(ctx,desc = None,rep = None):
用户= ctx.author
等待ctx.author.send('```请解释一下错误`''')
responseDesc = await bot.wait_for('message',check = lambda message:message。 author == ctx.author,timeout = 300)
description = responseDesc.content
等待ctx.author.send('````请e提供此bug的图片/视频''''')
responseRep = await bot.wait_for('message',check = lambda message:message.author == ctx.author,timeout = 300)
复制= 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)
消息=等待adminBug.send(embed = embed)
#在此处为表情符号中的表情符号添加3个反应(不同的表情符号):
表示表情符号:
等待消息.add_reaction (表情符号)
@ bot.event
异步定义on_reaction_add(reaction,user):
message = reaction.message
msg = message.content
表情符号= reaction.emoji
如果user.bot:
如果emoji == \u2705:
返回
固定= bot.get_channel(733722567449509958)
等待修复。发送(msg)
elif emoji ==&U0001F6AB:
notBug = bot.get_channel(733722584801083502)
等待notBug.send(消息)
elif emoji == quotu274C:
notFixed = bot.get_channel(733722600706146324)
等待notFixed.send (消息)
else:
return
bot.run(TOKEN)
您必须使用,它返回对象。您将能够获取 message_id
并使用最终得到嵌入:
@ bot.event
异步定义on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
msg =等待channel.fetch_message(payload.message_id)
embed = msg.embeds [0]
emoji = payload.emoji
如果user.bot:
如果emoji == emoji 1,则返回
:
固定= bot.get_channel(733722567449509958)
等待固定。send(embed = embed)
elif emoji == emoji 2:
notBug = bot.get_channel(733722584801083502)
等待notBug.send(embed = embed)
elif emoji == ; emoji 3:
notFixed = bot.get_channel(7 33722600706146324)未修复
固定。发送(嵌入=嵌入)
否则:
返回
NB: payload.emoji
返回,将其与原始Unicode进行比较可能不再起作用。
I am trying to make a system where when you react to an emoji, it will send that message (depending on what emoji you reacted with) - to another text-channel, now it is returning this instead of the actual message:
<Message id=733788372891467838 channel=<TextChannel id=733721953134837861 name='admin-bug' position=1 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 have tried making to use .content
on the variable, but it still does not work, and it gives me errors:discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message
Here is my code:
import discord
from discord.ext import commands
import asyncio
TOKEN = '---'
bot = commands.Bot(command_prefix='!!')
emojis = ["\u2705", "\U0001F6AB", "\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
msg = message.content
emoji = reaction.emoji
if user.bot:
return
if emoji == "\u2705":
fixed = bot.get_channel(733722567449509958)
await fixed.send(msg)
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)
You have to use on_raw_reaction_add()
, which returns a RawReactionActionEvent
object. You'll be able to get the message_id
and to use fetch_message
to finally get the embed:
@bot.event
async def on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
msg = await channel.fetch_message(payload.message_id)
embed = msg.embeds[0]
emoji = payload.emoji
if user.bot:
return
if emoji == "emoji 1":
fixed = bot.get_channel(733722567449509958)
await fixed.send(embed=embed)
elif emoji == "emoji 2":
notBug = bot.get_channel(733722584801083502)
await notBug.send(embed=embed)
elif emoji == "emoji 3":
notFixed = bot.get_channel(733722600706146324)
await notFixed.send(embed=embed)
else:
return
NB: payload.emoji
returns a discord.PartialEmoji
, comparing it to raw unicode might not work anymore.
这篇关于Discord.py-机器人发送有关消息而不是消息的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!