Creating Rule agreement when someone join

情到浓时终转凉″ 提交于 2021-01-27 09:36:33

问题


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:\Users\ezter\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "D:\programing\Discord Bots\Osis Nation\Start.py", line 31, in on_member_join
    role = discord.utils.get(bot.roles, name="Default")
  File "C:\Users\ezter\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 296, in __getattr__
    raise AttributeError(msg.format(self.__class__, name))
AttributeError: '<class 'discord.ext.commands.bot.Bot'>' object has no attribute 'roles'

I used this code to do it

#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! \n 2. Be kind, \n 3. Use common sense, \n 4. No swearing, \n 5. No racism or bullying, \n 6. No advertising, \n 7. Do not chat in #music Text or Voice channels, \n 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. \n 9. Do not use or abuse bot commands you should not be using! \n 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)

回答1:


I did it using this code

    #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! \n 2. Be kind, \n 3. Use common sense, \n 4. No swearing, \n 5. No racism or bullying, \n 6. No advertising, \n 7. Do not chat in #music Text or Voice channels, \n 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. \n 9. Do not use or abuse bot commands you should not be using! \n 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)



回答2:


I think the easiest way to do this would be to have the @everyone role be very restricted. Then have another role, @citizen (or whatever you want to call it) that is more permissive:

@bot.event
async def on_member_join(member):
    print("A member just joined and his name is" + member.name)
    citizen = discord.utils.get(member.server.roles, name="citizen")

    # DM user with rules
    await bot.send_message("Hello {0.mention}, welcome to {0.server.name}".format(member))
    await bot.send_message(member, Rules)
    dm = await bot.send_message(member, "Type !agree to agree")

    # get response
    check = lambda s: s.lower().startswith("!agree")
    msg = await bot.wait_for_message(channel=dm.channel, author=member, check=check)

    await bot.add_roles(member, citizen)


来源:https://stackoverflow.com/questions/51882207/creating-rule-agreement-when-someone-join

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!