KickMe Command(Python)

huangapple go评论116阅读模式
英文:

KickMe Command (python)

问题

  1. 我一直在制作一个 Discord 机器人,如果你说了他的一些命令,比如 !help,它会踢掉你。不知道问题出在哪里,我尝试了一切但都没用。这个机器人是用 Python 代码制作的:
  2. ```python
  3. import discord
  4. from discord.ext import commands
  5. intents = discord.Intents.default()
  6. intents.members = True
  7. TOKEN = '你的令牌'
  8. bot = commands.Bot(command_prefix='!', intents=intents)
  9. @bot.event
  10. async def on_ready():
  11. print(f'已登录为 {bot.user.name} ({bot.user.id})')
  12. @bot.event
  13. async def on_message(message):
  14. if message.content == "!help":
  15. if message.author.guild_permissions.kick_members:
  16. await message.channel.send(f"{message.author.mention},你因使用该命令而被踢出。")
  17. await message.author.kick(reason="使用了 '!help' 命令")
  18. else:
  19. await message.channel.send(f"{message.author.mention},你没有权限使用该命令。")
  20. await bot.process_commands(message)
  21. bot.run(TOKEN)

我期望当我说 "!help" 时,它会将我踢出。

  1. <details>
  2. <summary>英文:</summary>
  3. I been making a discord bot that will kick you if you say some of his commands like !help idk what is the problem I tried everything it didn&#39;t work the bot is made with python code:

import discord

from discord.ext import commands

intents = discord.Intents.default()

intents.members = True

TOKEN = 'no'

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event

async def on_ready():

  1. print(f&#39;Logged in as {bot.user.name} ({bot.user.id})&#39;)

@bot.event

async def on_message(message):

  1. if message.content == &quot;!Help&quot;:
  2. if message.author.guild_permissions.kick_members:
  3. await message.channel.send(f&quot;{message.author.mention}, you&#39;ve been kicked for using the command.&quot;)
  4. await message.author.kick(reason=&quot;Used the &#39;!Help&#39; command&quot;)
  5. else:
  6. await message.channel.send(f&quot;{message.author.mention}, you don&#39;t have permission to use that command.&quot;)
  7. await bot.process_commands(message)

bot.run(TOKEN)

  1. I was expecting when I say !Help it will kick me
  2. </details>
  3. # 答案1
  4. **得分**: 0
  5. 您需要在这里添加一些意图。
  6. 现在,您需要将`message_content`作为一个意图添加以读取消息内容。您还可以使用`discord.Intents.all()`来直接导入所有必要的意图(*请确保在[开发者门户](https://discord.com/developers/applications)中启用它们*)
  7. **您的新代码:**
  8. ```py
  9. intents = discord.Intents.default()
  10. intents.members = True
  11. intents.message_content = True # 添加此行以读取消息的内容
  12. bot = commands.Bot(command_prefix='!', intents=intents)
  13. # 代码的其余部分

有关更多信息,请参阅文档

英文:

You are missing some Intents here.

You are now required to add message_content as an Intent to read a message. You can also use discord.Intents.all() to directly import all the necessary Intents (Make sure to enable them in the Developer Portal as well)

Your new code:

  1. intents = discord.Intents.default()
  2. intents.members = True
  3. intents.message_content = True # Add this to read the content of the message
  4. bot = commands.Bot(command_prefix=&#39;!&#39;, intents=intents)
  5. # Rest of the code

Refer to the Docs for more information on this.

huangapple
  • 本文由 发表于 2023年7月13日 22:23:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680480.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定