Reputation: 67
How to make a discord bot kick someone when they say a trigger word? Like for example when someone says 'idiot' they will get kicked from the server.
Here is what I tried:
**import discord
import time
from discord.ext import commands
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready?")
@client.event
async def on_message(message):
if message.content.find("lol") != -1:
await message.channel.send("HI!")
@client.event
async def on_message(message):
if message.content.find('matei') != -1:
await kick('minionulLuiMatei#5893')
return
client.run(token)**
Upvotes: 0
Views: 1046
Reputation: 3602
You cannot have multiple on_message
events. You have to form them into one.
A post that explains it pretty well: Why multiple on_message events will not work
Now to your question. You can use two methods to filter the words and kick a member:
First method: Filters all messages and looks to see if the word Idiot
appears at any point in a sentence.
async def on_message(message):
if "Idiot" in message.content:
Second method:
Checks if the word Idiot
only appears at the beginning of the sentence.
async def on_message(message):
if message.content.startswith("Idiot"):
Then to kick a member you use the following function:
await message.author.kick(reason=None)
Your entire code would be:
@client.event
async def on_message(message):
if "Idiot" in message.content: # Method 1
await message.author.kick(reason=None) # Kick the author of the message, reason is optional
if message.content.startswith("Idiot"): # Method 2
await message.author.kick(reason=None)
Upvotes: 1