discord.py 检查它是否是正确的服务器或公会

时间:2021-07-18 17:18:27

标签: python discord discord.py

我正在尝试检查从哪个服务器调用命令,以便我可以向不同的服务器发送不同的响应

我想要这样的东西,但我不知道如何实现

@bot.event
async def on_message(message):
  #    get the server's id in which the message was sent
  guild = discord.guild
  #    one of my server's id
  server1_ID = bot.get_guild(865307645434658856)

  if guild == server1_ID:
    if message.content.startswith('!Ping Roles'):
      embedVar = discord.Embed(
        title="Ping Roles", 
        description="", 
        color=discord.Color.blue(),
        )

      await message.channel.send(embed=embedVar)

1 个答案:

答案 0 :(得分:0)

discord.guild 是整个模块,你想得到一个 discord.Guild

的实例
guild = message.guild
server1 = bot.get_guild(865307645434658856)

if guild == server1:
    ...