英文:
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'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'Logged in as {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}, you've been kicked for using the command.")
await message.author.kick(reason="Used the '!Help' command")
else:
await message.channel.send(f"{message.author.mention}, you don't have permission to use that command.")
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='!', intents=intents)
# Rest of the code
Refer to the Docs for more information on this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论