Creating Rule agreement when someone join(有人加入时创建规则协议)
本文介绍了有人加入时创建规则协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个机器人,它将新成员设置为只能查看一个频道并且必须就规则达成一致才能使用服务器的角色.我写了这个来做到这一点,但我一直收到这个错误.
I want to a bot that will set the new member to a role that can only view one channel and have to agree on rules in order to use the server. I have wrote this to do it but I keep getting this error.
Ignoring exception in on_member_join
Traceback (most recent call last):
File "C:UsersezterAppDataLocalProgramsPythonPython36libsite-packagesdiscordclient.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "D:programingDiscord BotsOsis NationStart.py", line 31, in on_member_join
role = discord.utils.get(bot.roles, name="Default")
File "C:UsersezterAppDataLocalProgramsPythonPython36libsite-packagesdiscordclient.py", line 296, in __getattr__
raise AttributeError(msg.format(self.__class__, name))
AttributeError: '<class 'discord.ext.commands.bot.Bot'>' object has no attribute 'roles'
我是用这段代码来做的
#Welcomer
@bot.event
async def on_member_join(member):
print("A member just joined and his name is" + member.name)
mid = member.id
role = discord.utils.get(bot.roles, name="Default")
role3 = discord.utils.get(member.server.roles, id="<479670838648635392>")
role2 = discord.utils.get(member.server.roles, id="<479692108953944081>")
await bot.add_roles(member, bot.get_)
Rules = "1. Do not DM the Owner or any other staff unless they have DMed you first!
2. Be kind,
3. Use common sense,
4. No swearing,
5. No racism or bullying,
6. No advertising,
7. Do not chat in #music Text or Voice channels,
8. Do not spam #applications if your application is accepted or denied! This is only to be used for submitting and staff members replying to the application.
9. Do not use or abuse bot commands you should not be using!
10. Do not @ any staff members unless it is an emergency. "
await bot.send_message(bot.get_channel('479685091749134346'), 'Hello <@%s>, Welcome to Osis Nation, please read all the rules carefully' % (mid))
await bot.send_message(bot.get_channel('479685091749134346'), (Rules))
await bot.send_message(bot.get_channel('479685091749134346'), 'If you agree write !Agree. If you do not agree write !Decline')
if member.content.upper().startwith("!Agree"):
await bot.send_message(bot.get_channel('479685091749134346'), 'You will be redirected to the server in 5 seconds')
time.sleep(5)
await bot.remove_roles(member, role)
推荐答案
我是用这段代码做到的
#Welcomer
@bot.event
async def on_member_join(member):
print("A member just joined and his name is" + member.name)
mid = member.id
role = discord.utils.get(member.server.roles, name="Default")
await bot.add_roles(member, role)
Rules = "1. Do not DM the Owner or any other staff unless they have DMed you first!
2. Be kind,
3. Use common sense,
4. No swearing,
5. No racism or bullying,
6. No advertising,
7. Do not chat in #music Text or Voice channels,
8. Do not spam #applications if your application is accepted or denied! This is only to be used for submitting and staff members replying to the application.
9. Do not use or abuse bot commands you should not be using!
10. Do not @ any staff members unless it is an emergency. "
await bot.send_message(bot.get_channel('479685091749134346'), 'Hello <@%s>, Welcome to Osis Nation, please read all the rules carefully' % (mid))
await bot.send_message(bot.get_channel('479685091749134346'), (Rules))
await bot.send_message(bot.get_channel('479685091749134346'), 'If you agree write !Agree. If you do not agree write !Decline')
@bot.event
async def on_message(message):
if message.content.upper().startswith("!AGREE"):
await bot.send_message(bot.get_channel('479685091749134346'), 'You will be redirected to the server in 5 seconds')
time.sleep(5)
role = discord.utils.get(message.server.roles, name="Default")
await bot.remove_roles(message.author, role)
这篇关于有人加入时创建规则协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:有人加入时创建规则协议


基础教程推荐
猜你喜欢
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01