[英]Custom bot command not working for discord bot made by discord.py
So basically I've created a discord bot.所以基本上我已经创建了一个不和谐的机器人。 It has the function to add role to users if the user writes a particular type of message on a particular channel.
如果用户在特定频道上写入特定类型的消息,它具有为用户添加角色的功能。 I've removed the default help command by this code
bot = commands.Bot(command_prefix='!', help_command=None)
but When the add role process is working the bot is ignoring the commands specially the help command the code is here:我已经通过这个代码
bot = commands.Bot(command_prefix='!', help_command=None)
删除了默认的帮助命令,但是当添加角色过程正在工作时,机器人会忽略命令,特别是帮助命令,代码在这里:
@bot.command()
async def help(ctx):
embeding = discord.Embed(description='Some Message')
await ctx.send(embed=embeding)
How can I fix this issue?我该如何解决这个问题?
I'm using on_message
function for assigning roles我正在使用
on_message
函数来分配角色
You haven't shown us your role command so there is only so much I can recommend.你还没有向我们展示你的角色命令,所以我只能推荐这么多。
First of all, you may be better of using the following code after you define your bot:首先,您最好在定义机器人后使用以下代码:
bot.remove_command('help')
Using an on_message
function will often also disable your other commands, so be sure to add this line of code to the bottom of your on_message
function:使用
on_message
函数通常也会禁用您的其他命令,因此请务必将这行代码添加到on_message
函数的底部:
await bot.process_commands(message)
import os
import discord
from discord import member
from discord import message
from discord import embeds
from discord import guild
import discord.ext.commands as commands
import dotenv
import random
intents = discord.Intents.default()
intents.members = True
dotenv.load_dotenv()
bot = commands.Bot(command_prefix='!', help_command=None)
@bot.event
async def on_ready():
print("I'm online")
print(bot.user.name)
print(bot.user.id)
print("-------------")
@bot.command()
async def help(ctx):
embeding = discord.Embed(description='Description I wanted')
await ctx.send(embed=embeding)
@bot.event
async def on_message(message):
cont = True
member = message.author
role = discord.utils.get(member.guild.roles, id=ROLE_ID)
splits = message.content.split("-")
if len(splits) != 4:
return
cont = False
try:
if (int(splits[0]) > 0 and int(splits[0]) < 1000):
cont = True
except ValueError:
cont = False
if splits[1] not in [#Some Options here]:
cont = False
if splits[2] not in [#Some Options here]:
cont = False
try:
if int(splits[3]) <= 2022:
cont = True
except ValueError:
cont = False
if cont and str(message.channel) == #SomeChannel:
await discord.Member.add_roles(member, role)
await message.channel.send(#Message on getting the role)
await bot.process_commands(message)
bot.run(os.getenv('TOKEN'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.