我正在寻找一种方法,以允许用户将他或她自己和另一个用户移动到不同的语音通道。我已经得到了为消息的作者工作的命令,但我无法找到一种方法来移动同一消息中的另一个用户。这个想法是用户将能够输入“n!协商其他用户”,并且它将把作者和其他用户移动到协商通道。
我希望能得到一些帮助,让我能够做到这一点。下面提供的代码不包括令牌和ids。
代码:
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")
发布于 2018-06-13 06:37:40
您应该使用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
移动到语音信道。
https://stackoverflow.com/questions/50826614
复制相似问题