Not sure that I need to use the both runs at the same time, but:
JavaScript
x
44
44
1
from multiprocessing.dummy.connection import Client
2
from telnetlib import DM
3
from typing_extensions import Required
4
import discord
5
from discord.utils import get
6
from discord.ext import commands
7
from dislash import InteractionClient, Option, OptionType
8
from dislash.interactions import *
9
10
client = discord.Client()
11
12
from message import *
13
@client.event
14
async def on_message(message):
15
if message.author == client.user:
16
return
17
18
User_id = message.author.id
19
20
if message.channel.id == 1009530463108476968:
21
NewMessage = message.content.split(' ', 1)[0]
22
LimitLenght = len(NewMessage) + 11
23
24
if len(message.clean_content) >= LimitLenght:
25
await message.delete()
26
await message.author.send("Hello, " + f"<@{User_id}>" + "nPlease, don't send any messages that break the **Counting-game** rules!nIt's forbidden to post a comment that is longer than 10 characters.")
27
28
# More code
29
30
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
31
32
bot = commands.Bot(command_prefix="!")
33
inter_client = InteractionClient(bot)
34
@inter_client.slash_command(name="help", description="Shows the help-menu")
35
36
async def help(ctx):
37
embedVar = discord.Embed(title="Test project", description="*The blue text is clickable.*n⠀", color=0x0000ff)
38
embedVar.add_field(name="Rules", value='To see rules write **/Rules**n⠀', inline=False)
39
await ctx.reply(embed=embedVar, delete_after=180)
40
41
42
bot.run('ToKeN')
43
client.run('ToKeN')
44
If you run this code and comment the “bot.run(‘ToKeN’)”, the first part of the code will work (def on_message), however the command ‘/help’ will not work. If you change it (comment ‘client.run(‘ToKeN’)’), the command ‘/help’ will work, but def on_message not.
What are the possible solutions? Thanks.
Advertisement
Answer
The .run
s block each other and prevent from running. You shouldn’t be using a client and a bot anyway. Use one commands.Bot
instead. It subclasses a Client
and it should be able to do everything you can do with the client.
JavaScript
1
13
13
1
bot = commands.Bot(command_prefix="!")
2
inter_client = InteractionClient(bot)
3
4
@bot.event
5
async def on_message(message):
6
7
8
@inter_client.slash_command(name="help", description="Shows the help-menu")
9
async def help(ctx):
10
11
12
bot.run(token)
13