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}")