故障排除参数 - 通道 ID


@client.slash_command(name = 'announce', description = 'Makes XYZ announcement in your announcements channel')
@application_checks.has_guild_permissions(moderate_members=True)
async def announce(interaction: nextcord.Interaction, channel: nextcord.TextChannel, *, msg):
await channel.send(f'{msg}')

我一直收到一个与SlashOptions相关的typehint错误。我只是试图将消息发送到由通道参数定义的指定通道中。为什么会出错?

@client.slash_command(name = 'announce', description = 'Makes XYZ announcement in your announcements channel')
@application_checks.has_guild_permissions(moderate_members=True)
async def announce(interaction: nextcord.Interaction, channel: nextcord.TextChannel, *, msg):
channel_id = channel.id
channel = client.get_channel(channel_id)
await channel.send(f'{msg}')

因此,为了回答我自己的问题,我回去查看了我之前写的代码,并意识到我从未指定我试图将消息发送到哪里,即使该频道是一个";论点";

为了解决这个问题,我意识到我需要指定用户通过使用输入的频道

#Creates a variable to collect channel: nextcord.TextChannel
channel_id = channel.id
# Now specifying the channel to send it to by grabbing the channel id of the requested channel.
channel = client.get_channel(channel_id)

这或多或少变成了较少的斜杠选项帮助,更多的是理解命令参数。永远不要放弃,伙计们!你最终会到达那里的。

最新更新