【问题标题】:Get channel by id in discord interactions在不和谐交互中通过 id 获取频道
【发布时间】:2022-10-05 14:47:08
【问题描述】:

我想在日志通道中发送日志消息,但为此我需要日志通道对象。

因为我使用了不和谐的交互来定义我的机器人,所以我不能使用 get_channel(id) 方法。我在discord-interactions documentation 中找不到通过 id 获取频道的方法。

提前致谢。

bot = interactions.Client(
    token = my_token,
    intents = interactions.Intents.ALL
    )

logs_channel = bot.get_channel(channel_id = 1015371164312424468)
Traceback (most recent call last):
  File "[...]", line 17, in <module>
    logs_channel = bot.get_channel(channel_id = 1015371164312424468)
AttributeError: 'Client' object has no attribute 'get_channel'

【问题讨论】:

  • 你试过fetch_channel() 吗?
  • 您使用discord-interactions 而不仅仅是discord.py 有什么原因吗?交互是 PyPi 上 v2.X 的一部分。
  • ConnerWolf08:我刚刚尝试过,但它不起作用,但我认为这是因为@stijndcl 是对的。明天我将重写我的代码并发布更新。谢谢您的帮助

标签: python discord.py discord-interactions


【解决方案1】:

您可以使用

logs_channel = await interactions.get(bot, interactions.Channel, object_id=your_channel_id)

获取频道。

您也可以加入支持服务器,因为您会更快地获得帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 2020-07-05
    • 2020-10-09
    • 2020-11-26
    • 2021-03-11
    • 2020-11-07
    • 2019-05-25
    相关资源
    最近更新 更多