Discord.py コマンドでロール付与をしたいのですがやり方がわかりません。助けてほしいです。
現在こんな感じです
import
import os import os; import ma as ma print(os.getcwd()) import subprocess import sys import random import asyncio import string import secrets import discord import os from discord.ext import commands import random from discord import Permissions import asyncio import shutil # 自分のBotのアクセストークンに置き換えてください # 読込むファイルのパスを宣言する file_name = "./token.txt" try: file = open(file_name) data = file.read() print(data) except Exception as e: print(e) finally: file.close() # 接続に必要なオブジェクトを生成 client = discord.Client() # 起動時に動作する処理 @client.event async def on_ready(): # 起動したらターミナルにログイン通知が表示される print('----------------') print('ログインしました') print('----------------') print('') print('BOT表示名:', client.user.name) # Botの名前 print('BOTのID:', client.user.id) # ID print('Dicord.pyのバージョン:', discord.__version__) ch = client.get_channel(947469205538762812) print('') guild_count = len(client.guilds) game = discord.Game(f'{guild_count} サーバーに導入されています') await client.change_presence(activity=discord.Game(name=game)) print('ログインしました {0.user}'.format(client)) await ch.send("BOTが起動しました!") # メッセージ受信時に動作する処理 @client.event async def on_message(message): guild_count = len(client.guilds) game = discord.Game(f'{guild_count} サーバーに導入されています') await client.change_presence(activity=discord.Game(name=game)) # メッセージ送信者がBotだった場合は無視する if message.author.bot: return # 「/neko」と発言したら「にゃーん」が返る処理 if message.content == 'spb!認証': passseta = random.randint(11111111, 9999999999) passsetb = random.randint(11111111, 9999999999) passsetc = random.randint(11111111, 9999999999) print(passseta) print(passsetb) print(passsetc) passlock = passseta+passsetb+passsetc channel = message.channel await channel.send("認証コードを30秒以内に送ってください") await channel.send(str('`認証コード : `')+str(passlock)) path = str('./')+str(message.guild.id)+str(message.channel.id) file_name = str('./')+str(message.guild.id)+str(message.channel.id) file = open(file_name, 'w') file.write(str(passlock)) file.close() file = open(file_name) file.close() # 待っているものに該当するかを確認する関数 def check(m): # メッセージが `おはよう` かつ メッセージを送信したチャンネルが # コマンドを打ったチャンネルという条件 path = str('./')+str(message.guild.id)+str(message.channel.id) file_name = str('./')+str(message.guild.id)+str(message.channel.id) f = open(path) file = open(file_name) data = file.read() print(data) file.close() file = open(file_name) file.close() return m.content == data and m.channel == channel try: # wait_forを用いて、イベントが発火し指定した条件を満たすまで待機する msg = await client.wait_for('message', check=check, timeout=30) # wait_forの1つ目のパラメータは、イベント名の on_がないもの # 2つ目は、待っているものに該当するかを確認する関数 (任意) # 3つ目は、タイムアウトして asyncio.TimeoutError が発生するまでの秒数 # asyncio.TimeoutError が発生したらここに飛ぶ except asyncio.TimeoutError: await channel.send(f'{message.author.mention}さん、認証時間切れです') else: # メンション付きでメッセージを送信する。 await channel.send(f'{msg.author.mention}さん、認証は成功しました') ROLE_ID = 975753269420884048 ID_ROLE_WELCOME = 975753269420884048 # 付けたい役職のID # channel_id から Channel オブジェクトを取得 role = guild.get_role(ID_ROLE_WELCOME) # リアクションを付けたメンバーに役職を付与 await member.add_roles(role) # 分かりやすいように歓迎のメッセージを送る await channel.send('いらっしゃいませ!') # Botの起動とDiscordサーバーへの接続 client.run(data)
まだ回答がついていません
会員登録して回答してみよう