KickMe Command(Python)

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

KickMe Command (python)

问题

我一直在制作一个 Discord 机器人,如果你说了他的一些命令,比如 !help,它会踢掉你。不知道问题出在哪里,我尝试了一切但都没用。这个机器人是用 Python 代码制作的:

```python
import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
TOKEN = '你的令牌'

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

@bot.event
async def on_ready():
    print(f'已登录为 {bot.user.name} ({bot.user.id})')

@bot.event
async def on_message(message):
    if message.content == "!help":
        if message.author.guild_permissions.kick_members:
            await message.channel.send(f"{message.author.mention},你因使用该命令而被踢出。")
            await message.author.kick(reason="使用了 '!help' 命令")
        else:
            await message.channel.send(f"{message.author.mention},你没有权限使用该命令。")
    await bot.process_commands(message)

bot.run(TOKEN)

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


<details>
<summary>英文:</summary>

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():

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

@bot.event

async def on_message(message):

if message.content == &quot;!Help&quot;:

    if message.author.guild_permissions.kick_members:

        await message.channel.send(f&quot;{message.author.mention}, you&#39;ve been kicked for using the command.&quot;)

        await message.author.kick(reason=&quot;Used the &#39;!Help&#39; command&quot;)

    else:

        await message.channel.send(f&quot;{message.author.mention}, you don&#39;t have permission to use that command.&quot;)

await bot.process_commands(message)

bot.run(TOKEN)

          

I was expecting when I say !Help it will kick me

</details>


# 答案1
**得分**: 0

您需要在这里添加一些意图。

现在,您需要将`message_content`作为一个意图添加以读取消息内容。您还可以使用`discord.Intents.all()`来直接导入所有必要的意图(*请确保在[开发者门户](https://discord.com/developers/applications)中启用它们*)

**您的新代码:**
```py
intents = discord.Intents.default()
intents.members = True
intents.message_content = True # 添加此行以读取消息的内容

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

# 代码的其余部分

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

英文:

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:

intents = discord.Intents.default()
intents.members = True
intents.message_content = True # Add this to read the content of the message

bot = commands.Bot(command_prefix=&#39;!&#39;, intents=intents)

# 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:

确定