【问题标题】:Fetch channel id using discord.py使用 discord.py 获取频道 ID
【发布时间】:2022-01-16 01:57:39
【问题描述】:

我正在尝试制作一个不和谐的机器人,它将发送频道 ID 以响应命令。例如,如果我输入命令 $channel,机器人将返回我发送命令的频道的频道 ID。

到目前为止,我有以下内容(命令前缀已设置为'$'):

client.command(name = 'channel')
    async def channel(ctx):
       await ctx.send(#not sure how to return channel id)

感觉有一个简单的解决方案,但我一直无法弄清楚。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    很简单:

    @client.command(name = 'channel')
    async def channel(ctx):
        await ctx.send(ctx.channel.id)
    

    ctx 存储许多信息 - 使用命令的用户、服务器、频道等 (check all)。获取channel 对象后即可获取id

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-25
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 2018-12-08
      • 2019-12-14
      • 2020-11-28
      相关资源
      最近更新 更多