简体   繁体   中英

discord.py - Can't send message to channel in other guild

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

Can't seem to send a message to a channel in other server/guild... The bot is present in both server (the one where the user issues a command and the one where the target channel is in)

no errors whatsoever in the console too. Any help or suggestion are appreciated

Try to do something like this:

@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)

Or you can fetch a channel:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM