【问题标题】:Why can't my main code run a custom module properly on Replit?为什么我的主代码不能在 Replit 上正确运行自定义模块?
【发布时间】:2022-01-08 20:55:45
【问题描述】:

我的 discord bot 的模块中有此代码以加入 vc:

import discord
import ffmpeg
from discord.ext import commands

client = commands.Bot(command_prefix = "!")

async def join(cxt):
  vc = ctx.message.author.voice_channel
  await client.join_voice_channel(channel)

但是主代码没有运行它,每当我尝试我的 !join 命令时它都不起作用。该机器人仍然在线,只是不会进入语音频道。该模块是命令。请帮忙!!

主要代码:

import discord
import os
import requests
import json
import random
import youtube_dl
import commands

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message):
  message.content = message.content.lower() 
  if message.author == client.user:
        return

client.run(os.getenv('TOKEN'))

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    voice_channel不是Member的属性,是ctx.message.author的类型。相反,您想在Member.voice 中查找VoiceState

    async def join(ctx):
      vc = ctx.message.author.voice.channel
      if vc:
        await vc.connect()
      else:
        # user isn't in voice
    

    同样,您无法使用Bot.join_voice_channel 连接到语音频道。您需要在VoiceChannelStageChannel 对象上调用connect()(如果存在,这就是为什么您应该检查Member.voice.channel 是否为None

    【讨论】:

    • 我试着按照你说的做,但是命令 !join 不起作用:(
    • @AmberD 运行命令时您是否在语音频道中?机器人帐户是否有足够的权限查看和加入该频道?您是否尝试过调试器和/或查看任何日志?
    • 是的,所有这些:(我正在进入一个语音频道,机器人拥有它需要的所有权限。
    • 那么调试时会发生什么?打印了哪些日志?
    • 它说由于某种原因没有找到不和谐模块?然而它一直很好地连接到不和谐。
    猜你喜欢
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 2010-10-14
    • 1970-01-01
    • 2014-01-17
    相关资源
    最近更新 更多