Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何制作一个';s事件仅在Discord.py中的某个服务器上发生_Python_Discord_Discord.py - Fatal编程技术网

Python 如何制作一个';s事件仅在Discord.py中的某个服务器上发生

Python 如何制作一个';s事件仅在Discord.py中的某个服务器上发生,python,discord,discord.py,Python,Discord,Discord.py,假设我想让我的机器人在服务器中发送某个消息时发送某个消息,例如: something = ["test, something"] @client.event async def on_message(message): if message.author == client.user: return channel = message.channel if any(word in message.content.lower() for word in somethin

假设我想让我的机器人在服务器中发送某个消息时发送某个消息,例如:

something = ["test, something"]

@client.event
async def on_message(message): 
    if message.author == client.user: return
    channel = message.channel
    if any(word in message.content.lower() for word in something):
        await channel.send("yikers")
    else:
        return 
我如何使这种情况仅在指定的通道、指定的服务器中发生


任何帮助都将不胜感激,谢谢

您只需检查
channel.id
即可查看消息是否位于正确的频道:

@client.event
async def on_message(message): 
    if message.author == client.user: return
    channel = message.channel
    if channel.id == 123:
        if any(word in message.content.lower() for word in something):
            await channel.send("yikers")
        else:
            return 
您可以通过将桌面discord客户端置于开发人员模式,或者通过添加类似

print(f"{channel.name} {channel.id}")