我一直在努力让自己成为一个机器人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')
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"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)