说我想让我的机器人在服务器中发送某些消息时发送某些消息,例如:
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
我如何使它仅在指定服务器上的指定通道中发生?
任何帮助将不胜感激,谢谢!
答案 0 :(得分:0)
您只需检查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客户端置于开发人员模式或添加
这样的行来获取ID。print(f"{channel.name} {channel.id}")