我正试图将我将YouTube视频制作成的Python音乐机器人转换为齿轮,所以我的主要Python Discord机器人文件并没有那么混乱。
我写的下面的代码不起作用。我阅读了有关齿轮的文档,但似乎找不到我做错的事情。
这是我尝试制作的代码,但这是
private void registerIconButton_Click(object sender, EventArgs e)
{
checkUser();
var connection = new MySqlConnection("Server=127.0.0.1;Database=book_library;user=root;password=root2");
connection.Open();
string insertQuery = "INSERT INTO `accounts` (username, password, email) VALUES ('" + usernameInputField.Text + "','" + passwordInputField.Text + "','" + emailInputField.Text + "')";
MySqlCommand command = new MySqlCommand(insertQuery, connection);
command.Parameters.Add("@username", MySqlDbType.VarChar).Value = usernameInputField.Text;
command.Parameters.Add("@password", MySqlDbType.VarChar).Value = passwordInputField.Text;
command.Parameters.Add("@email", MySqlDbType.VarChar).Value = emailInputField.Text;
if (checkUser())
{
MessageBox.Show("This username already exists!");
}
else
{
if (command.ExecuteNonQuery() == 1)
{
}
else
{
MessageBox.Show("ERROR");
}
}
connection.Close();
}
答案 0 :(得分:2)
两个问题:
bot
替换为self.bot
。在rpgmusic
,join
,leave
和play
命令中,更改:
voice = get(bot.voice_clients, guild=ctx.guild)
收件人:
voice = get(self.bot.voice_clients, guild=ctx.guild)
self
,而不是ctx
:@commands.command(pass_context=True)
async def rpgmusic(self, ctx)
@commands.command(pass_context=True)
async def join(self, ctx)
@commands.command(pass_context=True)
async def play(self, ctx)
此外,由于您拥有join
函数,因此可以在rpgmusic
中等待它(您也不需要global voice
):
@commands.command(pass_context=True)
async def rpgmusic(ctx, self):
await self.join(ctx)
await ctx.send(f'Playing some RPG music in {channel}.')
sleep(3)
voice.play(discord.FFmpegPCMAudio('rpgmusic.mp3'), after=lambda e: print(f'RPG music in {channel} has finished playing.'))
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.volume = 0.05