【问题标题】:discord.py - Can't send message to channel in other guilddiscord.py - 无法向其他公会的频道发送消息
【发布时间】:2022-01-07 19:03:19
【问题描述】:
async def sendmessage(ctx, channelID=None, content=None):
  if channelID == None:
      print("ERROR: NSB01")
  else:
     await bot.get_channel(channelID).send(content)

似乎无法向其他服务器/公会中的频道发送消息...机器人存在于两台服务器中(用户发出命令的服务器和目标频道所在的服务器)

控制台中也没有任何错误。任何帮助或建议表示赞赏

【问题讨论】:

  • 我假设context manager (ctx) 知道公会/用户,它调用了一个命令。因此,我会说如果在另一个不和谐中进行呼叫,则不可能在另一个不和谐中发送消息
  • 可能是这样。但是,当我获取消息的通道 ID(通过 on_message 事件),将其存储在全局变量中,然后从另一个服务器发出的另一个命令中使用它时,它就起作用了。 @bot.command() async def reply(ctx, args): await bot.get_channel(GLOBALID.channel.id).send(args)

标签: python discord discord.py


【解决方案1】:

尝试做这样的事情:

@bot.command()
async def sendmessage(ctx, channelID: int = None, content=None):
  if channelID is None:
      print("ERROR: NSB01")
  else:
     await bot.get_channel(channelID).send(content)

或者你可以获取一个频道:

channel = await bot.fetch_channel(channelID)
await channel.send(content)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 2021-03-24
    • 2021-04-04
    • 1970-01-01
    • 2021-09-18
    • 2014-01-30
    相关资源
    最近更新 更多