You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Discord机器人的await消息中提及指定频道?代码求助

解决Discord机器人无法正确提及指定频道的问题

直接在消息里写#playground只会被识别为普通文本,Discord不会将其解析为可点击的频道提及。要正确提及频道,需要使用Discord专属的频道提及格式:<#频道ID>。

修改后的代码示例

@bot.command()
async def prov(ctx):
    # 替换为你实际的playground频道ID
    playground_channel_id = 123456789012345678
    if ctx.channel.id == 1028873503010717717:
        # 使用<#频道ID>格式生成可识别的频道提及
        await ctx.send(f"The bot is disabled in this channel! Try in <#{playground_channel_id}>")
    else:
        # 可在此添加else分支的逻辑
        await ctx.send("Bot is available for use here!")

获取频道ID的方法

如果不知道playground频道的ID,可按以下步骤操作:

  • 打开Discord设置,进入「高级」选项
  • 开启「开发者模式」
  • 回到服务器,右键点击playground频道,选择「复制ID」

内容的提问来源于stack exchange,提问作者jean

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 04:25:18