Reputation: 21
I have been trying to make myself a bot for my ArmA 3
unit, and upon doing so I have tried to create an Enlisting
command, which changes the users existing Nickname within the server to the one that they enlist with (Their ArmA
soldier name). But I am having some trouble figuring out how to do this. I'll leave my code down below for you to look at and hopefully figure out a solution :
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
Client = discord.Client()
client = commands.Bot(command_prefix = "+.")
@client.event
async def on_ready():
print("ToLate Special Operations Reporting For Duty")
await client.change_presence(game=discord.Game(name="By Slay > $enlist", type=3))
print("For more information: Please contact Slay on twitter @OverflowEIP")
@client.event
async def on_message(message):
if message.content.upper().startswith('+.ENLIST'):
client.change_nickname(message.content.replace('changeNick', ''))
client.run('token')
Upvotes: 2
Views: 11310
Reputation: 60994
change_nickname
is a coroutine, so you have to await
it. You're also not really using commands
properly. You should be defining separate coroutines for each command and decorating them with the client.command
decorator. (You also don't need Client
, commands.Bot
is a subclass of discord.Client
)
from discord.ext.commands import Bot
from discord.utils import get
client = commands.Bot(command_prefix = "+.")
@client.event
async def on_ready():
print("ToLate Special Operations Reporting For Duty")
await client.change_presence(game=discord.Game(name="By Slay > $enlist", type=3))
print("For more information: Please contact Slay on twitter @OverflowEIP")
@client.command(pass_context=True)
async def enlist(ctx, *, nickname):
await client.change_nickname(ctx.message.author, nickname)
role = get(ctx.message.server.roles, name='ARMA_ROLE') # Replace ARMA_ROLE as appropriate
if role: # If get could find the role
await client.add_role(ctx.message.author, role)
client.run('token')
enlist(ctx, *, nickname)
means we accept commands like
+.enlist apple
+.enlist bag cat
+.enlist "dog eat"
and will assign those users (the person who called the command) the nicknames
apple
bag cat
"dog eat"
Upvotes: 2