我正在寻找一种方法,允许用户将他或她自己和另一个用户移动到另一个语音通道。我已经获得了为消息作者工作的命令,但我找不到在同一消息中移动另一个用户的方法。这个想法是用户可以键入" n!negotiate [Other User]"它会将作者和其他用户移动到谈判频道。
我希望能帮助我如何做到这一点。下面提供的代码不包括令牌和ID。
代码:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
Client = discord.Client() #Initialise Client
client = commands.Bot(command_prefix = "n!") #Initialise client bot and prefix
@client.event
async def on_ready():
print("Logged in as:")
print(client.user.name)
print("ID:")
print(client.user.id)
print("Ready to use!")
@client.event
async def on_message(check): #Bot verification command.
if check.author == client.user:
return
elif check.content.startswith("n!check"):
await client.send_message(check.channel, "Nations Bot is online and well!")
async def on_message(negotiation): #Negotiate command. Allows users to move themselves and other users to the Negotiation voice channel.
if negotiation.author == client.user:
return
elif negotiation.content.startswith("n!negotiate"):
author = negotiation.author
voice_channel = client.get_channel('CHANNELID')
await client.move_member(author, voice_channel)
client.run("TOKEN")
答案 0 :(得分:1)
您应该使用discord.ext.commands
。您正在导入它,但实际上并未使用任何功能。
from discord.ext import commands
import discord
bot = commands.Bot(command_prefix = "n!") #Initialize bot with prefix
@bot.command(pass_context=True)
async def check(ctx):
await bot.say("Nations Bot is online and well!")
@bot.command(pass_context=True)
async def negotiate(ctx, member: discord.Member):
voice_channel = bot.get_channel('channel_id')
author = ctx.message.author
await bot.move_member(author, voice_channel)
await bot.move_member(member, voice_channel)
bot.run('TOKEN')
我们使用converter接受Member
作为输入。然后,我们从invocation context解析邮件的作者,并将Member
移至语音频道。