本文介紹了有人加入時創建規則協議的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想要一個機器人,它將新成員設置為只能查看一個頻道并且必須就規則達成一致才能使用服務器的角色.我寫了這個來做到這一點,但我一直收到這個錯誤.
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)
這篇關于有人加入時創建規則協議的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!