【jishaku】discord botでpythonのコマンドを実行する方法

| 2022/05/25 07:32:56 | 811 | cat:Python |


はい!今回は、discord.pyのbotで、pythonのコマンドやコードを動かす方法を紹介していきます!

では、まず、以下のコマンドを実行してください。 pip install jishaku できない場合は py -m pip install jishaku を実行してください。 discord.pyは以下のコマンドで入れられます。 py -m pip install discord.py そしたら、メモ帳などを開いてください。(僕は今VScode持ってないのでIDLEを使います。) (botの作成方法は省略します) そしたら、以下のコードを入力します。

import discord
from discord.ext import commands
from jishaku.features.python import PythonFeature
from jishaku.features.root_command import RootCommand

bot = commands.Bot(command_prefix='好きなプレフィクス', help_command=None)
TOKEN = 'ここにアクセストークン'

class MyBot(commands.Bot):
    async def is_owner(self, user: discord.User):
        if something:  
            return True

        return await super().is_owner(user)

@bot.event
async def on_ready():
    print("-----------")
    print("起動しました")
    print("-----------")

@bot.command()
async def loadjsk(ctx):
    yourID = あなたのID
    if ctx.message.author.id == yourID or ctx.message.author.id == friendID:
        bot.load_extension('jishaku')
        print("success")
        print("https://github.com/Gorialis/jishaku")
        await ctx.send("📩`jishaku`")

bot.run(TOKEN)

コードの解説

import discord #discord.pyを読み込む
from discord.ext import commands #プレフィクスなどを利用可能にする
from jishaku.features.python import PythonFeature #jishakuを読み込む
from jishaku.features.root_command import RootCommand #jishakuを読み込む
class MyBot(commands.Bot):
    async def is_owner(self, user: discord.User):
        if something:  
            return True

        return await super().is_owner(user)
#このクラスを読み込むことでbot作成者のみがjishakuを利用できるようになる(推奨)
@bot.command()
async def loadjsk(ctx):
    yourID = あなたのID
    if ctx.message.author.id == yourID or ctx.message.author.id == friendID:
        bot.load_extension('jishaku')
        print("success")
        print("https://github.com/Gorialis/jishaku")
        await ctx.send("📩`jishaku`") #jishakuを読み込んだことを知らせるメッセージ

@bot.event
async def on_ready():
    print("-----------")
    print("起動しました")
    print("-----------")
#起動メッセージ

jishakuの使い方

まず、jishakuをロードします。

コマンド

簡単な計算や エラー表示も printももちろん実行できます。 アンロード(プレフィクスがmc!のばあい)は、 mc!jsk unload jishaku でできます。

みんなも使ってみてね!

sonya4327JE(sonyakun)

RANK: VIP

送られたステッカー🎁

🎉

応援ステッカーを送ろう🎉


{まだ未搭載です}

スポンサーリンク

Python
solo-thudner
524 回視聴   2023/01/03 09:06:47
Python
NEPTARUNE
390 回視聴   2022/08/27 03:13:32
ニュース
sonya4327JE(sonyakun)
443 回視聴   2022/05/16 07:40:34
その他
sonya4327JE(sonyakun)
808 回視聴   2022/02/25 21:05:48
ニュース
sonya4327JE(sonyakun)
460 回視聴   2022/05/19 06:57:45
sonya4327JE(sonyakun)
1035 回視聴   2022/06/05 07:43:10
リドレイン
463 回視聴   2022/05/14 13:43:01
ニュース
nennneko5787 ◆NOrufLSRl.
297 回視聴   2023/03/25 08:13:44
その他
コマンド
yuitomi
927 回視聴   2022/05/15 17:11:10
ニュース
しゅとく(shuuucream)
332 回視聴   2022/08/07 21:31:18
質問・教えて!
cba8b0b4-3314-4626-a604-78bd3569e3f0
403 回視聴   2022/06/15 17:28:56
その他
nennneko5787 ◆NOrufLSRl.
399 回視聴   2022/07/16 15:28:46
solo-thudner
92 回視聴   2024/04/03 08:41:47
nennneko5787 ◆NOrufLSRl.
242 回視聴   2023/04/23 08:50:17
03de3806-00eb-40df-8487-db0e2e83248b
351 回視聴   2022/08/07 17:59:41
ニュース
あけっちゃん
1291 回視聴   2022/05/23 19:48:10