我有一个正在努力改进的机器人.它被称为主持人机器人,我正在努力添加新命令.我只是在任何地方都找不到代码.
I have a bot that I'm trying to make better. It's called moderator bot and I'm working on adding new commands. I just can't find the code anywhere.
当用户加入服务器时,如何让主持人机器人赋予用户角色.以及如何让它由服务器所有者配置,以便机器人可以在不同的服务器上使用?
How do I get moderator bot to give user roles when they join the server. And how do I make it configurable by the server owner so that the bot can be used over different servers?
我还希望它 DM 所有者命令,以便他们可以看到它以及只有所有者设置的角色才能访问该命令.
I also want it to DM the owner commands so they can see it along with only owner-set roles being able to access that command.
这听起来很先进,而且可能是,但是有人可以为我编写代码或告诉我如何制作吗?
It sounds advanced and probably is, but can someone out there write the code for me or tell me how to make that?
1) 要让bot在成员加入时赋予角色,你需要有add_roles()
在您的 on_member_join
事件中.这可以通过
1) To make the bot give a member a role when they join, you need to have add_roles()
in your on_member_join
event. This can be accomplished with
@bot.event
async def on_member_join(member):
role = discord.utils.get(member.server.roles, id="<role ID>")
await bot.add_roles(member, role)
2) 要为每个服务器自定义角色,您需要一些文件来保存服务器 ID,以及在用户加入时提供的角色 ID(我个人会使用.db
文件和 sqlite3 从 python 编辑它,但你可以做任何你想做的事).您还需要稍微编辑我给出的 on_member_join
示例,以根据文件中的 member.server.id
选择角色 id,并在 on_member_join
中使用角色 id代码>discord.utils.get()
2) To have the role be customized for each server, you would need some file to hold the server id, and the role id to be given when the user joins (I personally would use a .db
file, and sqlite3 to edit it from python, but you can do whatever you want).
You would also need to slightly edit the on_member_join
example I gave to select the role id based on the member.server.id
from the file, and use the role id in discord.utils.get()
3) 要让机器人 DM任何人 获得默认帮助消息,请将 pm_help=True
添加到您的 Bot()代码>参数.要将您的部分命令发送给普通用户并仅发送给所有者,您需要创建一个新的帮助命令.为此,您需要在代码顶部附近添加
bot.remove_command('help')
,然后创建一个名为 help 的命令.然后,要将命令仅发送给所有者,请添加
3) To have the bot DM anyone the default help messages, add pm_help=True
to your Bot()
parameters. To have part of your commands the average user and all sent to only the owner, you will need to make a new help command. To do this, you will need to add bot.remove_command('help')
near the top of your code, and then create a command called help. Then, to have commands only sent to the owner, add
if ctx.message.author.id == ctx.message.server.owner.id:
await bot.send_message(ctx.message.author, <help message>)
到你的帮助命令.
希望对你有帮助
这篇关于如何让我的 Python discord 机器人在加入时赋予角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!