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

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

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

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Q&A

解決済

1回答

1528閲覧

discord.py実行したコマンドが二回されたことになります

Libe

総合スコア13

Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

0グッド

0クリップ

投稿2021/10/05 09:49

編集2021/10/05 09:51

#自分がしたいこと
コマンドを送ったとき一回しか送信されないようにしたい

ファイル構成

Githubサイト |--cogs | |-_init_.py | LibeCog.py main.py

main.py

py

1from discord.ext import commands 2import traceback 3 4from datetime import datetime, timedelta 5import datetime 6 7INITIAL_EXTENSIONS = ['cogs.LibeCog' 8] 9 10now = datetime.datetime.now() 11 12 コグとして用いるクラスを定義。 13 14 15class LibeBot(commands.Bot): 16 def __init__(self, command_prefix): 17 スーパークラスのコンストラクタに値を渡して実行。 18 super().__init__(command_prefix) 19 20 INITIAL_COGSに格納されている名前から、コグを読み込む。 21 エラーが発生した場合は、エラー内容を表示。 22 for cog in INITIAL_EXTENSIONS: 23 try: 24 self.load_extension(cog) 25 except Exception: 26 traceback.print_exc() 27 28 async def on_ready(self): 29 print('--------------------------------------') 30 print('Logged on as {0}!'.format(self.user)) 31 print('-------------------------------------') 32 print(self.user.name) 33 print('--------------------------------------') 34 print(self.user.id) 35 print('-------------------------------------') 36 print('ログインしました。') 37 print('-------------------------------------') 38 print(now.date()) 39 print('--------------------------------------') 40 41 42 43 44if __name__ == '__main__': 45 bot = LibeBot(command_prefix='.') 46 bot.run('TOKEN')

LibeCog.py

py

1import discord 2import logging 3import abc 4import requests 5from discord.ext import tasks, commands 6import aiohttp 7from pprint import pprint 8import asyncio 9import json 10import typing 11import traceback 12import random 13import traceback 14import time 15import re 16import traceback 17from discord.ext import commands 18from datetime import datetime, timedelta 19import datetime 20import sys 21 22now = datetime.datetime.now() 23 24#intents = discord.Intents.all() 25 26# コグとして用いるクラスを定義。 27class LibeCog(commands.Cog): 28 29 @commands.command() 30 async def delay_send(self, ctx): 31 async with ctx.typing(): # 送られてきたチャンネルで入力中と表示させる 32 await asyncio.sleep(5) # 重い処理をwith内で書く。(一例) 33 await ctx.send("処理完了") 34 35 @commands.command() 36 async def ping(self, ctx): 37 await ctx.send('pong!') 38 39 40 41 42 @commands.Cog.listener() 43 async def on_message(self, message): 44 45 print('メッセージが来たよ→ {0.author}: {0.content}'.format(message)) 46 47 if message.content.startswith('/id'): 48 await message.channel.send('PaL_Libe') 49 50 if message.content == '!bot': 51 await message.channel.send('```BOT discordバージョン起動中です。```') 52 53 if message.content.startswith('Hi'): 54 await message.channel.send(message.author.mention + 'こんちゃーす') 55 56 if message.content.startswith('/nhk'): 57 await message.channel.send( 58 message.author.mention + 59 'https://gendai.ismedia.jp/mwimgs/2/7/-/img_27d1ecc00191cbbf4d98e1129f2399f544134.jpg' 60 ) 61 62 if message.content.startswith('/2'): 63 await message.channel.send( 64 message.author.mention + 65 'https://img.huffingtonpost.com/asset/5c6389752300007601224077.jpeg?ops=1200_630' 66 ) 67 68# if message.content.startswith('/日にち'): 69 # await message.channel.send(f"```{now.date()}です。```") 70 71def setup(bot): 72 print('LibeCogファイルを読み込んだよ!') 73 bot.add_cog(LibeCog(bot))

init.py

from . import LibeCog from . import cogs from . import cog

開発環境python-3.9.5 discord.py==1.7.3

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

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

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

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

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

guest

回答1

0

自己解決

ごめんなさい二個実行してました

投稿2021/10/05 10:07

Libe

総合スコア13

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.45%

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

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

質問する

関連した質問