所以我试图建立一个只允许在某个频道中说一个单词的机器人,尽管我已经获得了第一位的设置,但是我不确定如何仅通过一个特定的频道来观看它
这是香港专业教育学院到目前为止的成果,甚至不确定它是否可以在...... p
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('mytoken')
client = discord.client()
@client.event
async def on_ready():
print(f'{client.user} has connected to discord!')
client.run(TOKEN)
client.on("message", (message) => {
if(message.content != "e") return message.delete()
});
答案 0 :(得分:0)
您应该使用on_message
事件,并检查该频道是否为您要查找的频道,并且消息中是否包含单词。对于每条消息,检查message.channel.id
是否等于特定频道的ID:
special_id = #the channel id you get by right clicking on a channel and click copy ID
special_word = 'your_word'
@client.event
async def on_message(message):
if message.channel.id == special_id:
if not special_word in message.content:
await message.channel.purge(1)#delete the message the user sent
await message.channel.send('you must have "{}" in your message in this channel'.format(special_word)