首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Discord Bot:如何移动消息作者提到的特定用户

Discord Bot:如何移动消息作者提到的特定用户
EN

Stack Overflow用户
提问于 2018-06-13 06:18:53
回答 1查看 2.4K关注 0票数 0

我正在寻找一种方法,以允许用户将他或她自己和另一个用户移动到不同的语音通道。我已经得到了为消息的作者工作的命令,但我无法找到一种方法来移动同一消息中的另一个用户。这个想法是用户将能够输入“n!协商其他用户”,并且它将把作者和其他用户移动到协商通道。

我希望能得到一些帮助,让我能够做到这一点。下面提供的代码不包括令牌和ids。

代码:

代码语言:javascript
复制
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")
EN

回答 1

Stack Overflow用户

发布于 2018-06-13 06:37:40

您应该使用discord.ext.commands。您正在导入它,但实际上并没有使用任何功能。

代码语言:javascript
复制
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移动到语音信道。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50826614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档