DiscordAPI 问题:无法发送空消息

时间:2021-05-04 12:17:28

标签: discord

这段代码一直在将我嵌入的消息从一个不和谐频道复制到另一个频道。

这突然发生了,直到昨天代码都运行良好。

import asyncio
import discord
from discord.ext import commands, tasks
from discord.ext.commands import Bot, CommandNotFound

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

FROM = removed for obv reasons  #ID_OF_CHANNEL_YOU_WANT_TO_COPY_FROM
TO = removed for obv reasons  #ID_OF_CHANNEL_YOU_ARE_COPYING_FROM
TO_CHANNEL = None
FROM_CHANNEL = None

@bot.event
async def on_ready():
    print("x channel to y channel ")
    global TO_CHANNEL
    global FROM_CHANNEL
    TO_CHANNEL = await bot.fetch_channel(TO)
    FROM_CHANNEL = await bot.fetch_channel(FROM)

@bot.event
async def on_message(message):
    if message.channel.id == FROM:
        print('1')
        if message.embeds:
            print('looping')
            for embed_ in message.embeds:
                print(f'Sent: embed to {FROM_CHANNEL.name}')
                await TO_CHANNEL.send(embed=embed_)
        elif message.attachments:
            print('2')
            for attachment in message.attachments:
                print(f'Sent: image url{attachment.url} to {FROM_CHANNEL.name}')
                await TO_CHANNEL.send(attachment.url)
        else:
            print('3')
            print(f'Sent: {message.content} to {FROM_CHANNEL.name}')
            await TO_CHANNEL.send(message.content)

    await bot.process_commands(message)

bot.run('出于明显原因删除')

这里是错误

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\User\Desktop\CODING\SHUBOT\MAIN\SHU\BOTS\TURTLES TO HUB RATINS.py", line 34, in on_message
    await TO_CHANNEL.send(message.content)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 935, in send
    data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 247, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message

0 个答案:

没有答案