如何踢用户 [英] How to kick users on command

查看:83
本文介绍了如何踢用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Python的了解并不多,并且仍在学习它。

I don't have much knowledge on Python, and still in the process of learning it.

我一直在大量修改使用python编码的开源Discord机器人。 Python 2.7。

I have been significantly modifying an open-source Discord bot coded in Python 2.7.

我想添加一个功能,使我可以根据命令踢用户。

I would like to add a feature that allows me to kick a user based on a command.

类似
[commandprefix] kickuser [userid]
但是我不知道如何使机器人从我发送的消息中抢走用户ID,以及当我试图使其变得超特定时我的第二个帐户作为测试,也不起作用。

Something like [commandprefix]kickuser [userid] But I have no idea how to make the bot grab the userid from the message I sent, and when I try to make it ultra-specific to kick my second account as a test, it doesn't work either.

    if message_content == ',purgeIdiots':
        await kick('userid')
        return

这是超具体代码,我可以在其中手动输入用户ID。但是我无法使它正常工作。

That's the ultra-specific code where I manually enter a userID into the document. But I cannot get it to work.

我是新手,很感谢您的帮助。

I'm extremely new and I'd appreciate some help.

推荐答案

如果您正在研究制作命令的过程,建议您进一步阅读一下discord.py的discord.ext.commands子库。

If you're looking into the process of making commands, I'd suggest looking further into reading about the discord.ext.commands sub-library of discord.py.

以下是它的常见问题,以及以下使用它的机器人示例:

Here's an FAQ about it, and an example of a bot using it following:


常见问题解答

示例示例

此扩展允许您使用前缀创建命令。

This extension will allow you to create commands using prefixes.

关于通过用户ID踢的问题,使用命令扩展可以执行以下操作:

In regards to your question about kicking via user id, with the command extension you could do something like:

@bot.command(pass_context = True)
async def kick(ctx, userName: discord.User):
    await bot.kick(userName)

我认为应该可以,但是我还不能编译它以便进行检查。但是,请确实了解有关命令扩展的更多信息,因为它比检查消息内容有更多帮助。

I believe that should work, but I can't compile it just yet to check. However, do learn more about the command extension as it'll help you out a lot more than checking messages for content.

您首先需要导入discord.ext,您可以执行在程序顶部使用discord.ext导入命令中的

You'll first need to import discord.ext, you can do that with from discord.ext import commands at the top of the program.

然后,您需要定义bot以确保您可以使用 @ bot.command 之类的东西,因为您将需要它。这样做是这样的: bot = commands.Bot(command_prefix =',',description = description),现在将逗号定义为命令前缀。

You'll then need to define bot to ensure you can use stuff like @bot.command, because you'll need that. This is done like this: bot = commands.Bot(command_prefix=',', description=description), with the comma being defined as the command prefix now.

这应该允许我最初添加的代码段起作用,以便用户能够键入,然后单击

This should allow the code snippet I added originally to function with a user being able to type ,kick <username>.

这篇关于如何踢用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆