我正在使用discord.py 在 python 中编写一个Discord Bot。我有一个禁止命令来禁止其他用户并向他们发送一条直接消息,通知他们有关禁止的信息。我似乎无法让它工作。
The script looks like this:
`import discord
from discord.ext import commands
print("Powerup initiated!")
print("Setting command prefix and intents")
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
intents.dm_messages = True
client = commands.Bot(command_prefix='!', intents=intents)
@client.event
async def on_ready():
await client.change_presence(activity=discord.Game(name="/help"))
print(f"{client.user} has connected to Discord!")
print("Powerup complete!")
print("--------------------------")
@client.command()
async def test(ctx):
await ctx.send("Bot's up and running!")
@client.command()
async def ban(ctx, member: discord.Member, *, reason=None):
await member.ban(reason=reason)
try:
dm_message = f'You have been banned from {ctx.guild} for {reason}.'
await member.send(dm_message)
except discord.Forbidden:
await ctx.send(f"Couldn'd DM {member.mention}. {member.mention} has been banned without a DM.")
else:
await ctx.send(f'{member.mention} has been banned and informed in his DMs.')
client.run('The Token of my bot')`
我尝试在我的 alt 上使用正常的 !ban 命令,它应该用 dm 禁止他,因为它是一个具有默认设置的新帐户。然而,我的 alt 没有收到 DM,机器人告诉我它无法发送 DM。
第一个: 转到您的 Discord 机器人的开发者门户应用程序 https://discord.com/developers/applications/(应用程序 ID)/information
旁注:如果由于某种原因上述方法不起作用,请仔细检查您是否在机器人权限部分下启用了所需的文本权限。要排除此变量,请在 discord 机器人权限计算器 中启用管理员访问权限,并重新邀请机器人访问您的服务器。