【发布时间】:2021-10-06 18:41:25
【问题描述】:
我正在尝试测试我是否可以将所有发送到 test_copy_channel 频道的消息复制并粘贴到 test_paste_channel
尽管机器人正在执行命令并正确记录嵌入,但我不断收到错误消息。
这是我正在使用的代码:
import discord
import os
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=',', intents=intents)
@bot.event
async def on_ready():
global test_paste_channel, test_copy_channel
test_paste_channel = bot.get_channel(868816978293452841)
test_copy_channel = bot.get_channel(808734570283139162)
print('bot is ready')
@bot.event
async def on_message(message):
# if message.author == bot.user:
# return
if message.channel == test_copy_channel:
await test_paste_channel.send(message.content)
print(message.channel)
if message.content.startswith('!test'):
embed_var = discord.Embed(
title= '''title''',
description= '''description''',
color= discord.Color.red()
)
embed_var.set_footer(text='footer')
await message.channel.send(embed=embed_var)
bot.run(os.getenv('TOKEN'))
所以我要做的是将!test 发送到test_copy_channel,这样机器人就会发送嵌入,然后尝试复制我的消息和嵌入
我的消息通过正常,但是当机器人尝试复制嵌入时,我收到此错误:
Ignoring exception in on_message
Traceback (most recent call last):
⠀⠀File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
⠀⠀⠀⠀await coro(*args, **kwargs)
⠀⠀File "main.py", line 25, in on_message
⠀⠀⠀⠀await test_channel.send(message.content)
⠀⠀File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 1065, in send data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
⠀⠀File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 254, in request
⠀⠀⠀⠀raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message
它似乎没有停止执行命令,并且代码似乎工作正常。
据我了解,当它尝试复制机器人发送的嵌入消息时会触发错误。
我只是想知道它为什么会触发此错误。
【问题讨论】:
标签: python discord discord.py