【问题标题】:Discord bot can't kick user who blocked the botDiscord 机器人无法踢出阻止该机器人的用户
【发布时间】:2022-01-18 19:57:38
【问题描述】:

几天前,我用 python 写了一个小不和谐机器人,它运行得很好。但我刚刚遇到了一个问题,似乎该机器人无法与阻止该机器人的用户进行交互(赋予角色、踢球等)。 有办法解决吗?

这样的功能不起作用:

import random as r
import discord
from discord.ext import commands
import asyncio

intents = discord.Intents.default()
intents.members = True

@client.event
async def on_member_join(member):
server_name = client.get_guild(802985801100165200)
await member.send(f'Willkommen auf {server_name}!')
print(1)
rolle = discord.utils.get(member.guild.roles, name='Member')
await member.add_roles(rolle)

@client.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx,member: discord.Member,*,reason=None):
await member.send(f'You were kicked from the Schnitzel Server {reason}')
await member.kick(reason=reason)
await ctx.send(f'Kicked {member} {reason}')

client.run(TOKEN)

【问题讨论】:

  • 我们需要更多信息。你写了什么?

标签: python discord discord.py


【解决方案1】:

您的机器人无法向阻止您的机器人的人发送消息。尝试这样做会引发discord.Forbidden 403 error

你想尝试,除了那个场景

原文:

await member.send(f'You were kicked from the Schnitzel Server {reason}')
await member.kick(reason=reason)
await ctx.send(f'Kicked {member} {reason}')

编辑:

try:
   await member.send(f'You were kicked from the Schnitzel Server {reason}')
except discord.Forbidden:
   await ctx.send("Failed to DM the user.") # will send if bot fails to DM the user
   # pass (if you don't want a failure indication and want to silently pass on error)
await member.kick(reason=reason) # this will function normally if bot fails to send message to user
await ctx.send(f'Kicked {member} {reason}')

【讨论】:

    猜你喜欢
    • 2021-07-27
    • 2021-02-24
    • 2020-09-22
    • 1970-01-01
    • 2011-03-23
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    相关资源
    最近更新 更多