Reputation: 9
SO I have seen how to make a bot that restrics users to use specific words, but can I also do it that a specific user cant use the words?
@client.event
async def on_message(message, user):
if user.has_role("cheffe"):
if any(word in message.content for word in hate_words):
await message.delete()
await message.channel.send("""You are not allowed to speak about animes!""")
else:
await client.process_commands(message)
else:
await client.process_commands(message)
Upvotes: 0
Views: 91
Reputation: 81
on_message
only takes in one parameter which is "Message"
you can find the docs here
You can get a member object through message.author
Upvotes: 1
Reputation: 3714
You currently have a variable (i assume list, or dict for peformance) 'hate_words' which contains forbidden words.
For example:
hate_words = ["foo", "bar"]
Then you check for forbidden words using
if any(word in message.content for word in hate_words):
...
If you want to specify the forbidden words per user,
you can change your data structure to be a dict of lists,
were the key to the dict is the User.name
property, e.g.:
hate_words_by_user = {
"user_name_1": ["foo", "bar"],
"user_name_2": ["bar", "baz"]
}
Now you can check the specific users sublist using:
# user.name from the parameter that your on_message function has
user_hate_words = hate_words_by_user[user.name]
if any(word in message.content for word in user_hate_words):
...
If you just want specific users not be able to use
the words in your single hate_words
list (I didn't fully get which of the two you meant), you could just add a variable
users_that_may_not_use_hate_words = ["user_name_1", "user_name_2"]
and then check like this:
if user.name in users_that_may_not_use_hate_words:
if any(word in message.content for word in hate_words):
...
Upvotes: 0