質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

724閲覧

DiscordBotのコマンドについて

Mikan0141

総合スコア23

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2023/05/11 10:22

実現したいこと

  • PythonでDiscordのコマンドに反応するプログラムを書きたい

内容

PythonでDiscordのコマンドに反応するプログラムを書いています。
実行しようとしたら以下のエラーが出ました。

エラーメッセージ

Traceback (most recent call last): File "C:\Pytho\mikan.py", line 6, in <module> from discord_slash import SlashCommand, SlashContext ModuleNotFoundError: No module named 'discord_slash'

該当のソースコード

Python

1import discord 2import asyncio 3import random 4from discord.ext import tasks 5from discord.ext import commands 6from discord_slash import SlashCommand, SlashContext 7import os 8 9bot = discord.Client(intents_discord.Intents.all()) 10slash_client = SlashCommand(bot, sync_commands=True) 11client = discord.Client() 12TOKEN = '-トークン-' 13 14@client.event 15async def on_ready(): 16 print('HelloWorld') 17 18@client.event 19async def on_message(message): 20 if message.author == client.user: 21 return 22 23 if message.content.startswith('$hello'): 24 await message.channel.send('Hello!') 25 26@slash_client.slash(name="botsay", description="bot") 27 await ctx.send(content="こんにちは") 28 29 30client.run(TOKEN)

試したこと

モジュール名をpip installのときの名前にしてみましたがハイフンでエラーが出てダメでした。

補足情報

DiscordBotはすべての権限を付けています。
実行したものは
pip install discord-py-interactions
pip install discord
です。
このサイトでの質問が初めてなのでテンプレートに頼りっきりで変なところがあるかもしれませんがよろしくおねがいします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

めちゃくちゃ古いバージョンのコードではないですか?
https://github.com/interactions-py/interactions.py/tree/3.0.3
2年前のバージョンです。

レポジトリ
https://github.com/interactions-py/interactions.py/
を見にいけばその様なモジュールはないとわかりますし、そんな書き方をしないのもreadmeを読めば分かります。


discord.py で書く方法を探した方が有益な気がしました。

投稿2023/05/11 11:35

quickquip

総合スコア11038

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Mikan0141

2023/05/11 21:45

ありがとうございます! 大幅に変えて import discord from discord.ext import commands bot = commands.Bot(command_prefix='/',intents=discord.Intents.all()) client = discord.Client(intents=discord.Intents.all()) TOKEN = '--TOKEN--' @client.event async def on_ready(): print('HelloWorld') @client.event async def on_message(message): if message.author == client.user: return if message.content.startswith('$hello'): await message.channel.send('Hello!') @bot.command() async def botsend(ctx): await ctx.send('HelloWorld') client.run(TOKEN) にしてみたらエラーはなくなったものの最初に'HelloWorld'と出てコマンドをいくら打っても実行されなくなってしまったのですがどうすればいいでしょうか?
Mikan0141

2023/05/11 22:23

import discord from discord.ext import commands intents = discord.Intents.all() intents.members = True bot = commands.Bot(command_prefix='!', intents=intents) @bot.command() async def hello(ctx): await ctx.send('Hello, World!') bot.run('-TOKEN-') とすればできました。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問