コマンドを実行すると役職を付与、ニックネームを変更したいです。
python
1 @commands.command() 2 async def agree(self, ctx, mcid): 3 if ctx.channel.id == 499427177444409366: 4 if mcid == "notid": 5 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 6 role1 = discord.utils.get(ctx.guild.roles, name="通知") 7 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 8 await ctx.author.add_roles(role, role1, role2) 9 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 10 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 11 await ctx.author.send(embed=embed) 12 await ctx.author.edit(ctx.author, ctx.author_name + "#非スポンサー") 13 else: 14 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 15 role1 = discord.utils.get(ctx.guild.roles, name="通知") 16 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 17 await ctx.author.add_roles(role, role1, role2) 18 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 19 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 20 await ctx.author.send(embed=embed) 21 await ctx.author.edit(ctx.author, mcid + "#非スポンサー") 22 if ctx.channel.id == 555051444596768789: 23 if mcid == "notid": 24 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 25 role1 = discord.utils.get(ctx.guild.roles, name="通知") 26 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 27 await ctx.author.add_roles(role, role1, role2) 28 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 29 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 30 await ctx.author.send(embed=embed) 31 await ctx.author.edit(ctx.author, ctx.author_name + "#非スポンサー") 32 else: 33 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 34 role1 = discord.utils.get(ctx.guild.roles, name="通知") 35 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 36 await ctx.author.add_roles(role, role1, role2) 37 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 38 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 39 await ctx.author.send(embed=embed) 40 await ctx.author.edit(ctx.author, mcid + "#非スポンサー") 41 else: 42 return
#追記
ですが、ニックネームを変更する方法がわかりません。
どうかご教授お願い致します。
#追記2
pythonのバージョンは3.6.6です。
discord.pyは1.0.0aです。
discord.pyのドキュメント等は既に確認済みです。
それでできませんでした。
どうかご教授ください。
#追記3
それでできませんでした。
について・・
以下を読んでも分からなかった部分を質問してください。
という部分から読んでできませんでした、という意味でした。わかりずらい表記をしてすみません。
ニックネームの変更がわかりません。
また、こういう場所で質問する場合はドキュメントをしっかり読んで、日本語じゃないなら翻訳を使いながら読み取ってそれで分からなければ聞くという流れで質問しなければ失礼だとわかってます。
なので、実装したいことを説明しますと、
!?agree Monster2408
と入力するとニックネームがMonster2408#非スポンサー
となるようにしたいです。
await ctx.bot.change_nickname(mcid + "#非スポンサー")
このようにしたり、ctx
をself.bot
やmcid
にしたり、ここを参考にawait after.edit(nick=last)
を使ってみたりと試行錯誤しましたが、ニックネームを変更する部分のみうまくできませんでした。
#追記3.5
どういう結果だったかを忘れていました。
コマンド実行時に同じようなエラーがでるといった感じです。
error
1Ignoring exception in command agree: 2Traceback (most recent call last): 3 File "C:\Users\enjoy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 62, in wrapped 4 ret = await coro(*args, **kwargs) 5 File "c:\Users\enjoy\OneDrive\デスクトップ\Python\DiscordBot\cogs\testcog.py", line 275, in agree 6 await ctx.bot.change_nickname(nick=ctx.author_name + "#非スポンサー") 7AttributeError: 'MyBot' object has no attribute 'change_nickname' 8 9The above exception was the direct cause of the following exception: 10 11Traceback (most recent call last): 12 File "C:\Users\enjoy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 898, in invoke 13 await ctx.command.invoke(ctx) 14 File "C:\Users\enjoy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 611, in invoke 15 await injected(*ctx.args, **ctx.kwargs) 16 File "C:\Users\enjoy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 71, in wrapped 17 raise CommandInvokeError(exc) from exc 18discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'MyBot' object has no attribute 'change_nickname'
#追記4
python
1 @commands.command() 2 async def agree(self, ctx, mcid): 3 if ctx.channel.id == 499427177444409366: 4 if mcid == "notid": 5 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 6 role1 = discord.utils.get(ctx.guild.roles, name="通知") 7 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 8 await ctx.author.add_roles(role, role1, role2) 9 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 10 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 11 await ctx.author.send(embed=embed) 12 await ctx.bot.change_nickname(nick=ctx.author_name + "#非スポンサー") 13 else: 14 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 15 role1 = discord.utils.get(ctx.guild.roles, name="通知") 16 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 17 await ctx.author.add_roles(role, role1, role2) 18 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 19 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 20 await ctx.author.send(embed=embed) 21 await ctx.change_nickname(mcid + "#非スポンサー") 22 if ctx.channel.id == 555051444596768789: 23 if mcid == "notid": 24 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 25 role1 = discord.utils.get(ctx.guild.roles, name="通知") 26 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 27 await ctx.author.add_roles(role, role1, role2) 28 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 29 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 30 await ctx.author.send(embed=embed) 31 await ctx.bot.change_nickname(nick=ctx.author_name + "#非スポンサー") 32 else: 33 role = discord.utils.get(ctx.guild.roles, name="m._.m(モン民)") 34 role1 = discord.utils.get(ctx.guild.roles, name="通知") 35 role2 = discord.utils.get(ctx.guild.roles, name="再認証者") 36 await ctx.author.add_roles(role, role1, role2) 37 embed = discord.Embed(title="{}さんの認証が完了しましたなの".format(ctx.author.name), description='', color=0xff0000) 38 embed.add_field(name="MLSBOTに関して・・・", value="当サーバーではあらゆる機能を持ったBOTがいます。\nその機能は<#499571567823421440>にて`!?help`と入力するとコマンド一覧が、\n<#546337968042803222>にて`何ができるの?`と聞いたり`何が話せるの?`と聞いたりすると機能がわかります。", inline=False) 39 await ctx.author.send(embed=embed) 40 await ctx.bot.change_nickname(mcid + "#非スポンサー")
これが最新のコードです。
回答1件
あなたの回答
tips
プレビュー