如何使用 pycord 在特定频道中发送消息?

How do I send a message in a specific channel with pycord?

背景资料:

我正在制作一个用于发布命令的机器人,我想让机器人在特定频道中发送消息并向用户发回消息以显示命令已发送。但是,我收到此错误:

错误

经过一段时间的等待,得到“应用程序没有响应”,我终于得到了错误:

Ignoring exception in on_interaction Traceback (most recent call last): File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/bot.py", line 727, in process_application_commands command = self._application_commands[interaction.data["id"]] KeyError: '956003758620426290'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 382, in _run_event await coro(*args, **kwargs) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/bot.py", line 1028, in on_interaction await self.process_application_commands(interaction) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/bot.py", line 742, in process_application_commands await self.sync_commands(unregister_guilds=[guild_id]) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/bot.py", line 685, in sync_commands await self.http.bulk_upsert_command_permissions(self.user.id, guild_id, guild_cmd_perms) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 357, in request raise HTTPException(response, data) discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In 0: Invalid application command id provided

代码:

import discord
import os
import random
import asyncio

testing_servers = [912361242985918464]
intents = discord.Intents().all()
bot = discord.Bot(intents=intents)

@bot.event
async def on_ready():
    print('Online!')


@bot.slash_command(guild_ids=testing_servers, name="announce", description="Make server announcements!")
async def announce(ctx, title, text, channel_id,anonymous=None):
    #response embed
    print(channel_id)
    #announcement embed
    embed_announce = discord.Embed(
        colour = discord.Colour.blue(),
        title=str(title),
        description = text
    )
    await channel_id.send(embed = embed_announce)

    embed = discord.Embed(
        colour=discord.Colour.blue(),
        title = "Sent!",
        description= "Check the channel to make sure you wrote the right thing!"
    )

    await ctx.respond(embed = embed)

过去的尝试:

我尝试通过以下方式获取频道:

bot.get_channel(channel_id)

我也尝试过使用频道 ID 和#channel

但是,我得到这个错误:

AttributeError: 'NoneType' object has no attribute 'send'

确保您发送的是整数 get_channel()

   await bot.get_channel(int(channel_id)).send(embed=embed_announce)