python 我已经在Replit中编程了一个Discord Bot命令,但该命令未在Discord Server中显示

v8wbuo2f  于 2023-08-02  发布在  Python
关注(0)|答案(1)|浏览(93)
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命令在机器人中没有成功实现。

inn6fuwd

inn6fuwd1#

只有当你的机器人在Discord中注册了至少一个全局或公会应用程序命令时,“支持命令”徽章才会出现。传统前缀命令(使用前缀和MESSAGE_CREATE事件处理的命令)不计入此标记。
请参阅应用程序命令上的this page,以及官方Discord Developers Discord中的this message,我将其粘贴在下面:

Hey everyone! We’ve got an announcement to share with you: we're testing a commands badge on bot profiles, which will help draw attention to the fact that a bot supports commands - as well as help educate users on features that bots have, which we know is something you all have requested.

If your app has at least one global command, you will see this badge show today!

What to know:

:dot: The badge will be displayed on the bot's user profile
:dot: The tooltip (when hovering over the badge) will say "Supports Commands"
:dot: Clicking on the badge itself will direct users to a web page that describes in more detail what slash commands are, what additional features bots can support, and other FAQ. If you haven’t seen this page yet, it’s here: https://discord.com/blog/welcome-to-the-new-era-of-discord-apps
:dot: All bots and apps are eligible! Slash commands, user commands, and message commands all count. All you need to do is register at least one global command for your app. (You can learn more about how to do this here: https://discord.com/developers/docs/tutorials/upgrading-to-application-commands)
:dot: If your app already meets this criteria, congrats!

Helping users understand how to get the most out of apps has been and will continue to be one of our top priorities. This is one thing we’re trying out, and there will be more coming soon! Enjoy.

字符串

相关问题