0

So I have been trying to make a verify command (.verify), where it needs an argument names and is supposed to make a role with their name and assign it to them and also is in supposed to be sent in a specific channel so the people aren't allowed to make roles themselves I thought it was the channel.id at first but I put print(ctx.message.channel.id) and it was the same so I knew that wasn't the error, but it doesn't make the role and doesn't give any role, and even no error! Please help me. Here is my code so far.

    @client.command(pass_context=True)
    async def verify(ctx, name):
      print(ctx.message.channel.id)
      if ctx.message.channel.id == 521645091098722305:
        await client.create_role(author.server, name=name)
        await client.say('Done! Welcome!')

If done thanks, Sincerely, Bread

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
Bread
  • 11
  • 1
  • 5
  • What version of discord.py are you using? If you're using 0.16, also called the async branch, then all ids are strings, so you should be checking `if ctx.message.channel.id == '521645091098722305'` instead – Patrick Haugh Dec 11 '18 at 14:29
  • I pretty sure I'm using the latest, because I just updated it a week or two ago. But I'll try anyways – Bread Dec 11 '18 at 20:43
  • Try `import discord; print(discord.__version__)`. To install the rewrite branch, follow the instructions here: https://stackoverflow.com/questions/50686388/how-to-install-discord-py-rewrite – Patrick Haugh Dec 11 '18 at 20:44
  • 1
    Thank you so much! I just changed it to a string and it made an error saying an error about author.server and then i changed it do ctx.message.author.server and it worked. Thank you! – Bread Dec 11 '18 at 20:47
  • Now I need to be able to add the role that was just created. My idea was await client.add_roles(ctx.message.author, name=name) but i had an error saying TypeError: add_roles() got an unexpected keyword argument 'name' – Bread Dec 11 '18 at 20:50
  • `create_role` will return a `Role` object. Capture that and pass it to `add_roles` – Patrick Haugh Dec 11 '18 at 20:52
  • I tried using this `role = discord.utils.get(member.server.roles, name=name)` `await client.add_roles(ctx.message.author, role)` but it just says member is not defined. – Bread Dec 12 '18 at 04:59
  • `member` isn't defined. You could use `ctx.server.roles` instead – Patrick Haugh Dec 12 '18 at 05:02
  • discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'server' – Bread Dec 12 '18 at 05:45
  • Try `ctx.message.server.roles` then. – Patrick Haugh Dec 12 '18 at 16:02
  • Now it has a python extension problem :/ File "C:\Users\Daniel\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 2915, in new_roles = utils._unique(role.id for role in itertools.chain(member.roles, roles)) AttributeError: 'NoneType' object has no attribute 'id' – Bread Dec 12 '18 at 20:35

1 Answers1

0

Use strings instead of integers for ids in the async branch. You also need to capture the Role that create_role makes, and pass that to add_roles

@client.command(pass_context=True)
async def verify(ctx, name):
  print(ctx.message.channel.id)
  if ctx.message.channel.id == '521645091098722305:
    role = await client.create_role(ctx.message.author.server, name=name)
    await client.add_roles(ctx.message.author, role)
    await client.say('Done! Welcome!')

The equivalent rewrite command would be

@client.command()
async def verify(ctx, name):
  print(ctx.channel.id)
  if ctx.channel.id == 521645091098722305:
    role = await ctx.guild.create_role(name=name)
    await ctx.message.author.add_roles(role)
    await ctx.send('Done! Welcome!')
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
  • I tried installing rewrite branch but it says `warning: templates not found in C:/Program Files/Git/mingw64/share/git-core/templates git: 'remote-https' is not a git command. See 'git --help'. Command "git clone -q https://github.com/Rapptz/discord.py C:\Users\Daniel\AppData\Local\Temp\pip-install-rtw2c0xr\discord.py" failed with error code 128 in None` – Bread Dec 12 '18 at 20:41
  • Try `pip install -U git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice]` – Patrick Haugh Dec 12 '18 at 20:43
  • Yep, installed it, but now some of my other commands aren't working. Should this happen? – Bread Dec 12 '18 at 20:55
  • The rewrite branch is a breaking change, so if you want to migrate your code you'll likely need to change some of it: https://discordpy.readthedocs.io/en/rewrite/migrating.html – Patrick Haugh Dec 12 '18 at 20:56
  • I use a logs_from in my clear command, the usage in the migration site doesn't make sense to me. How would I change it? `@client.command() async def clear(ctx, amount=100): channel = ctx.message.channel messages = [] async for message in logs_from(channel, limit=int(amount)): messages.append(message) await message.delete(message) await TextChannel.delete_messages(messages) await client.say('Messages deleted')` sorry if you can't read it I'm new to this – Bread Dec 12 '18 at 21:09
  • Use `await ctx.channel.purge(limit=int(amount))` instead – Patrick Haugh Dec 12 '18 at 21:13
  • Back to normal conversation, for client.create_role, it says command doesn't exist so I changed it to guild.create_role which was noted in the migration site, but it said guild is not defined. Do I put guild in the attributes or? – Bread Dec 12 '18 at 21:20
  • I just realised that it only supports one word, I tried making it support two word but it makes two roles, one with the first name and the other with the last name. (Some peoples names could be 3 words or 4 words.) I used this setup `async def verify(ctx, *args): print(ctx.message.channel.id) name = ' ' for word in args: name += word name += ' '` – Bread Dec 13 '18 at 06:38
  • Use the keyword only argument syntax: https://discordpy.readthedocs.io/en/rewrite/ext/commands/commands.html#keyword-only-arguments – Patrick Haugh Dec 13 '18 at 13:27