前提・実現したいこと
Discord.pyで同じ名前のテキストチャンネルとボイスチャンネルを作り、2つの名前をコマンドで編集したり、削除したりする機能を作りたいです。 テキストチャンネルは編集、削除が出来ますが、ボイスチャンネルの方でエラーが発生しています。
編集用のコマンドと削除用のコマンドでエラーが発生しています。
発生している問題・エラーメッセージ
#編集用のコマンドで発生しているエラー discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'edit' #削除用のコマンドで発生しているエラー discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'delete'
該当のソースコード
python
1#チャンネル作成 2@bot.command() 3async def create(ctx, name = '部屋'): 4 Guild = bot.get_guild(836935048359182359) 5 category= bot.get_channel(872803559572398081) 6 channel = Guild.get_channel(873062525124624474) 7 if ctx.channel.id == 873062525124624474: 8 await Guild.create_text_channel(name, category = category) 9 await Guild.create_voice_channel(name, category = category, user_limit = 3) 10 await channel.send(f'{ctx.author.mention}さんが「{name}」を作りました。') 11 else: 12 channel = ctx.message.channel 13 embed=discord.Embed(title="このチャンネルでは`s!create [name]`は使用できません。", description="このメッセージとコマンドは数秒後に削除されます。", color=0xff0000) 14 message = await channel.send(embed=embed) 15 await asyncio.sleep(10) 16 await message.delete() 17 18 19#チャンネル編集 20@bot.command() 21async def edit(ctx, new_name = ''): 22 if ctx.channel.category_id == 872803559572398081 and ctx.channel.id != 873062525124624474: 23 guild = bot.get_guild(836935048359182359) 24 channel1 = ctx.message.channel 25 v_channel = discord.utils.get(guild.voice_channels, name=channel1) 26 await channel1.edit(name = new_name) 27 await v_channel.edit(name = new_name) 28 await channel1.send(f'チャンネル名を「{new_name}」に変更しました。') 29 elif new_name == '': 30 channel = ctx.message.channel 31 embed=discord.Embed(title="変更したい名前[new_name]を入力してください。", description="このメッセージとコマンドは数秒後に削除されます。", color=0xff0000) 32 message = await channel.send(embed=embed) 33 await asyncio.sleep(10) 34 await message.delete() 35 else: 36 channel2 = ctx.message.channel 37 embed=discord.Embed(title="このチャンネルでは`s!edit [new_name]`は使用できません。", description="このメッセージとコマンドは数秒後に削除されます。", color=0xff0000) 38 message = await channel2.send(embed=embed) 39 await asyncio.sleep(10) 40 await message.delete() 41#チャンネル削除 42@bot.command() 43async def delete(ctx): 44 if ctx.channel.category_id == 872803559572398081 and ctx.channel.id != 873062525124624474: 45 guild = bot.get_guild(836935048359182359) 46 channel = ctx.message.channel 47 v_channel = discord.utils.get(guild.voice_channels, name=channel) 48 await channel.delete() 49 await v_channel.delete() 50 channel1 = guild.get_channel(873062525124624474) 51 await channel1.send(f'{ctx.author.mention}さんが「{channel}」を削除しました。') 52 else: 53 channel = ctx.message.channel 54 embed=discord.Embed(title="このチャンネルでは`s!delete`は使用できません。", description="このメッセージとコマンドは数秒後に削除されます。", color=0xff0000) 55 message = await channel.send(embed=embed) 56 await asyncio.sleep(10) 57 await message.delete() 58 59bot.run(config.TOKEN)
試したこと
Channel ID、 Guild ID の確認
補足情報(FW/ツールのバージョンなど)
Discord.py 1.7.3
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。