Python Discord Bot在服务器中不响应(给定的所有权限),但在dm中工作完全正常 &g



我使用Pycord在Python中编码Discord bot。我需要添加斜杠命令稍后,所以没有不和。py

机器人以前工作得很好。现在它只响应DM中的命令,而不响应服务器中的命令。

所有必需的权限都已给定。机器人在线显示。

import discord
import os
import json
import requests
from discord.ext import commands
import aiohttp
# Gets token from a file
from dotenv import load_dotenv
load_dotenv('discord_token.env')
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
bot = commands.Bot(command_prefix="--")
bot.remove_command("help")
@bot.event
async def on_ready():
print('The bot is logged in '+str(len(bot.guilds))+' servers!')
await bot.change_presence(status=discord.Status.online, activity=discord.Game("--help"))
@bot.command()
async def a(ctx):
try:
embed = discord.Embed(title="A", color=0xCC0066)
except Exception as ex:
embed = discord.Embed(title="Something went wrong with A", color=0xCC0066)
print("Error in A")
print(ex)
finally:
await ctx.channel.send(embed=embed)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
embed = discord.Embed(title="Command not found. Please try --help", color=0xCC0066)
await ctx.channel.send(embed=embed)
else:
print("Command error has occurred")
print(error)
bot.run(DISCORD_TOKEN)

当没有启用intent时,会出现此问题

转到discord.com/developers/applications

选择您的应用程序

转到bot部分

向下滚动并启用所有意图

添加到你的代码中。

intents = discord.Intents.default()
intents.message_content = True
bot=commands.Bot(command_prefix="--",case_insensitive=True,intents=intents)
bot.remove_command("help")

最新更新