import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
roles_to_monitor = [ROLE_ID]
monitored_channels = [CHANNEL_ID]
@bot.event
async def on_ready():
print(f'We have logged in as {bot.user}')
@bot.event
async def on_message(message):
if message.channel.id in monitored_channels and message.mentions:
for mentioned_user in message.mentions:
mentioned_roles = [
role for role in mentioned_user.roles if role.id in roles_to_monitor
]
if mentioned_roles:
role_names = ', '.join([role.name for role in mentioned_roles])
warning_message = f"{message.author.mention}, be careful, you pinged HR+ !"
await message.channel.send(warning_message)
embed = discord.Embed(description=warning_message,
color=discord.Color.red())
embed.set_image(
url="IMAGE_LINK")
embed.add_field(
name="Additional Message",
value=("MESSGAE")
await message.channel.send(embed=embed)
break
allowed_roles = [ROLE_ID]
@bot.command()
async def kick(ctx, member: discord.Member):
if any(role.id in allowed_roles for role in ctx.author.roles):
await member.kick()
await ctx.send(f"{member.mention} has been kicked.")
print(f"Command enabled: /kick invoked by {ctx.author.name}")
else:
await ctx.send("You don't have permission to use this command.")
bot.run('BOT_TOKEN')
字符串
控制台输出:
2023-07-31 03:51:55 INFO discord.客户端使用静态令牌登录
2023-07-31 03:51:56 INFO discord.gateway Shard ID None has connected to Gateway(Session ID:############).
我们已登录为AURP#4566
问题:
机器人不支持命令。我试图通过邀请链接和调试代码来修复它,但问题仍然存在。
由于未知的原因,机器人没有获得“支持Commnad”徽章,这简单地表明Kick命令在机器人中没有成功实现。
1条答案
按热度按时间inn6fuwd1#
只有当你的机器人在Discord中注册了至少一个全局或公会应用程序命令时,“支持命令”徽章才会出现。传统前缀命令(使用前缀和
MESSAGE_CREATE
事件处理的命令)不计入此标记。请参阅应用程序命令上的this page,以及官方Discord Developers Discord中的this message,我将其粘贴在下面:
字符串