我一直在努力让自己成为ArmA 3
单位的机器人,在这样做的时候,我尝试创建一个Enlisting
命令,将服务器内用户现有的昵称更改为他们征募(他们的ArmA
士兵名字)。但我在弄清楚如何做到这一点时遇到了一些麻烦。我将把我的代码留在下面让你看一看,并希望找到一个解决方案:
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')
答案 0 :(得分:1)
change_nickname
是一个协程,所以你必须await
它。您还没有真正正确使用commands
。您应该为每个命令定义单独的协同程序,并使用client.command
装饰器对它们进行装饰。 (您也不需要Client
,commands.Bot
是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)
表示我们接受
+.enlist apple
+.enlist bag cat
+.enlist "dog eat"
并将为这些用户(调用命令的人)分配昵称
apple
bag cat
"dog eat"