JavaScript
x
69
69
1
import discord
2
import random
3
from discord.ext import commands
4
from discord.ext.commands import Bot
5
6
7
client = discord.Client()
8
bot_prefix = "."
9
client = commands.Bot(command_prefix=bot_prefix, case_insensitive=True)
10
11
ban_words = ['fuck',
12
'shit']
13
14
15
@client.event
16
async def on_ready():
17
print("Shefkata e spremen")
18
19
20
async def on_message(ctx, message):
21
if message.content.lower() in ban_words:
22
await message.delete()
23
24
25
@client.command(pass_context=True, case_insensitive=True)
26
async def ping(ctx):
27
await ctx.send(f'pong {round(client.latency * 1000)}ms')
28
29
30
@client.command(pass_context=True, case_insensitive=True)
31
async def shefe(ctx):
32
await ctx.send("Sho sakash kopile")
33
34
35
@client.command(pass_context=True, case_insensitive=True)
36
async def zdravo(ctx):
37
pozdravi = ["Zdravo",
38
"Kaj si be",
39
"Zdravo sinka"]
40
await ctx.send(f'{random.choice(pozdravi)}')
41
42
43
@client.command(pass_context=True, aliases=['8ball'], case_insensitive=True)
44
async def _8ball(ctx, *, question):
45
responses = ["It is certain.",
46
"It is decidedly so.",
47
"Without a doubt."]
48
await ctx.send(f'Question: {question}nAnswer: {random.choice(responses)}')
49
50
51
@client.command(pass_context=True, case_insensitive=True)
52
async def dabs(ctx):
53
broj = random.randint(0, 1000)
54
if broj == 666:
55
await ctx.send("JA PRONAJDE NAJRETKATA PORAKAnIMASHE 0.1% SHANSA DA TI SE PADNI")
56
await ctx.send("https://imgur.com/poI3bZl")
57
broj = random.randint(0, 100)
58
if broj == 69:
59
await ctx.send("https://imgur.com/OOgEaLb")
60
else:
61
await ctx.send("https://imgur.com/RFlt0bz")
62
63
64
@client.command(pass_context=True, case_insensitive=True)
65
async def commands(ctx):
66
await ctx.send(".pingn.shefen.zdravon.8balln.dabs")
67
68
client.run('token')
69
The commands that used the bot prefix to run stopped working after adding a client event to delete messages containing certain keywords. I recently started coding so all help would be very appreciated. The discord.py documentation is kinda complicated so i cannot find what i am looking for. For more details please ask me in the comments.
Advertisement
Answer
You have to use this:
JavaScript
1
2
1
await client.process_commands(ctx)
2
Without this, none of your commands will work.
So, your event will look like this:
JavaScript
1
10
10
1
@client.event
2
async def on_message(ctx):
3
message = ctx.content.lower()
4
for word in ban_words:
5
if word in message:
6
await ctx.delete()
7
return
8
9
await client.process_commands(ctx)
10
Also, you forgot to add @client.event
. Without it, the on_message()
function won’t act as a listener.