当成员以用户的形式出现时,不会发送消息

发布于 2025-02-11 05:22:58 字数 500 浏览 2 评论 0 原文

@bot.command(name='kick')
async def kick(ctx, message, member: discord.Member, *, reason=None):
    if reason is None:
        reason = " no reason provided"
    await ctx.guild.kick(member)
    await ctx.send(f'User {member.mention} has been kicked. \n Reason: {reason}')

    if member is False:
        await message.channel.send("User can't be found")

这是我的代码。我尝试了多种不同的方法来做到这一点,但是它们都没有起作用。踢命令是我想要的,但是当我尝试踢一个机器人不认识到它的人时,从未说过找不到用户。我为何如此感到困惑,我想要一些帮助。谢谢。 :)欢迎任何建议或解决方案。

@bot.command(name='kick')
async def kick(ctx, message, member: discord.Member, *, reason=None):
    if reason is None:
        reason = " no reason provided"
    await ctx.guild.kick(member)
    await ctx.send(f'User {member.mention} has been kicked. \n Reason: {reason}')

    if member is False:
        await message.channel.send("User can't be found")

This is my code. I have tried multiple different ways to do this but none of them have worked. The kick command works which is what I wanted but when I try to kick someone that the bot doesn't recognize it never says that the user can't be found. I'm confused as to why this is, and I would like some help, please. Thanks. :) Any suggestions or solutions are welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

茶底世界 2025-02-18 05:22:58

这是针对那些正在研究这个问题并需要帮助的人。请注意,我使用了这篇文章的答案以找到此问题的答案。这是代码:

@bot.command(name='kick')`
async def kick(ctx, message, member: discord.Member, *, reason=None):
    if reason is None:
        reason = " no reason provided"
    await ctx.guild.kick(member)
    await ctx.send(f'User {member.mention} has been kicked. \n Reason: {reason}')


@kick.error  # Error handler for the kick command
async def kick_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):  # Check which error occurs
        await ctx.send("User not found.")  # Send your message`

感谢所有试图帮助我解决这个问题的人。抱歉,如果这个问题让那些遇到这个问题感到困惑。这是我第一次在Stackoverflow上问一个问题,因此目前我并不是最好的问题。

This is for those who are looking at this question and need help. Please note that I used part of this post's answer to find the answer to this question. Here's the code:

@bot.command(name='kick')`
async def kick(ctx, message, member: discord.Member, *, reason=None):
    if reason is None:
        reason = " no reason provided"
    await ctx.guild.kick(member)
    await ctx.send(f'User {member.mention} has been kicked. \n Reason: {reason}')


@kick.error  # Error handler for the kick command
async def kick_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):  # Check which error occurs
        await ctx.send("User not found.")  # Send your message`

Thank you to everyone who tried to help me with this question. Sorry if this question was confusing for those who came across this. This is my first time asking a question on stackoverflow so I'm not really the best with asking questions on this platform at the moment.

苦行僧 2025-02-18 05:22:58
async def kick(ctx, member : discord.Member, *, reason=None):
  if reason is None:
    await member.send(member.name +f" has been kicked by {ctx.author}")
    await ctx.send(f"user {member} has been kicked by {ctx.author}")
    await member.kick(reason=reason)
  else:
    await member.send(member.name +f" has been kicked by {ctx.author}, because:" + str(reason))
    await ctx.send(f"user {member} has been kicked by {ctx.author} because" + str(reason))
    await member.kick(reason=reason)

尝试一下

async def kick(ctx, member : discord.Member, *, reason=None):
  if reason is None:
    await member.send(member.name +f" has been kicked by {ctx.author}")
    await ctx.send(f"user {member} has been kicked by {ctx.author}")
    await member.kick(reason=reason)
  else:
    await member.send(member.name +f" has been kicked by {ctx.author}, because:" + str(reason))
    await ctx.send(f"user {member} has been kicked by {ctx.author} because" + str(reason))
    await member.kick(reason=reason)

try this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文