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

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

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

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

Twitter

Twitterは、140文字以内の「ツイート」と呼ばれる短文を投稿できるサービスです。Twitter上のほぼ全ての機能に対応するAPIが存在し、その関連サービスが多く公開されています。

Python

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

Q&A

0回答

837閲覧

discord.pyでtweetしたい

karikaricorn

総合スコア0

Discord

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

Twitter

Twitterは、140文字以内の「ツイート」と呼ばれる短文を投稿できるサービスです。Twitter上のほぼ全ての機能に対応するAPIが存在し、その関連サービスが多く公開されています。

Python

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

0グッド

0クリップ

投稿2022/04/24 00:16

print("Running twitter_for_discord") print("Running twitter_for_discord") import os import sys import time import discord import urllib.request import urllib.error import tweepy #cmdでpip listを入力し、os,sys,time,discord,urllib.request,urllib.error,time,requests,tweepyがインストールされていることを確認してください。 #インストールされてない場合、pip install の後にimportの後に書いてあるものを入力し、インストールしてください。cmdは管理者権限で実行することをお勧めします。 TOKEN = '' #Discord developersサイトでアプリを作成してbotのトークンを''の中に入力してください。 client = discord.Client() CHANNEL_ID = 967436908382781542 #Discordでチャンネルを右クリックするとIDがコピーできるので「=」の直後にペーストしてください。(開発者用の設定をオンにしてください。) #ログイン処理 async def greet(): channel = client.get_channel(CHANNEL_ID) await client.change_presence(activity=discord.Game(name='Twitter for Discord')) print("ログインしました。\n") await channel.send('ログインしました。') #ログイン処理終了 @client.event async def on_ready(): await greet() @client.event async def on_message(message): if message.author.bot: return def check(msg): return msg.author == message.author if message.content == '/login': if message.author.guild_permissions.administrator: await message.channel.send('ログイン認証...') API_KEY='' #Twitter Developersで生成したアプリのapi_keyを''の中に入力してください。 API_KEY_SECRET='' #Twitter Developersで生成したアプリのapi_key_secretを''の中に入力してください。 def get_oauth_token(url:str)->str: querys = urllib.parse.urlparse(url).query querys_dict = urllib.parse.parse_qs(querys) return querys_dict["oauth_token"][0] auth = tweepy.OAuthHandler(API_KEY, API_KEY_SECRET) redirect_url = auth.get_authorization_url() oauth_token = get_oauth_token(redirect_url) auth.request_token['oauth_token'] = oauth_token auth = tweepy.OAuthHandler(API_KEY, API_KEY_SECRET) api = tweepy.API(auth) redirect_url = auth.get_authorization_url() redirect_url print(redirect_url) await message.channel.send(redirect_url) await message.channel.send('PINを入力してください。') def check(msg): return msg.author == message.author verifier = await client.wait_for("message", check=check) print(verifier.content) verfire_code = await message.channel.send(verifier.content) await verfire_code.add_reaction('❌') auth.request_token['oauth_token_secret'] = verifier.content try: auth.get_access_token(verifier.content) except tweepy.TweepError: print("アクセストークンの入手に失敗しました。") with open("C:/Users/kusik/Desktop/新しいフォルダー (2)/auth_info.txt",mode="w") as file: text = "key:{}\nsecret:{}".format(auth.access_token,auth.access_token_secret) file.write(text) if auth.access_token is None : if auth.access_token_secret is None : print('PINコードが間違っています。') await message.channel.send('PINを入力してください。') return else: auth.set_access_token(auth.access_token, auth.access_token_secret) print("access_token:",auth.access_token) print("access_token_secret",auth.access_token_secret) print("認証が完了しました。") await message.channel.send("認証が完了しました。") await message.channel.send("ログインが完了しました。") api = tweepy.API( auth, wait_on_rate_limit=True ) me = api print('ようこそ') img = new_func1(api) url = img await message.channel.send('ようこそ') embed_message = discord.Embed(title=me,description=me,color=0xff0000) embed_message.set_thumbnail(url=url) await message.channel.send(embed=embed_message) while True : def check(msg): return msg.author == message.author command_discord = await client.wait_for("message", check=check) if message.author.bot: return if command_discord.content == '/tweet': await message.channel.send('ツイートする内容を送信してください。') wait_message = await client.wait_for("message",check=check) api.update_status(wait_message.content) print("ツイートを送信しました。→"+wait_message.content) await message.channel.send('ツイートを送信しました。') elif command_discord.content == '/purge': channel = client.get_channel(967436908382781542) #CHANNEL_IDを任意のチャンネルIDに入れ替えてください。 await channel.purge(limit=None) await message.channel.send('メッセージ履歴をすべて削除しました。(˙◁˙)パア') time.sleep(1.5) await channel.purge(limit=None) elif command_discord.content == '/logout': await message.channel.send('ログアウトしました。') break else : await message.channel.send('管理者権限がない者は実行できません。') elif message.content == '/purge': if message.author.guild_permissions.administrator: channel = client.get_channel(967436908382781542) #ここも同じくCHANNEL_IDを任意のIDに入れ替えてください。 await message.channel.send('履歴をすべて削除しますか?y/n') y_n = await client.wait_for("message",check=check) print(y_n.content) if y_n.content == 'y': await channel.purge(limit=None) await message.channel.send('メッセージ履歴をすべて削除しました。(˙◁˙)パア') time.sleep(1.5) await channel.purge(limit=None) elif y_n.content == 'Y': await channel.purge(limit=None) await message.channel.send('メッセージ履歴をすべて削除しました。(˙◁˙)パア') time.sleep(1.5) await channel.purge(limit=None) elif y_n.content == 'n': await message.channel.send('キャンセルしました。(˙◁˙)パア') elif y_n.content == 'N': await message.channel.send('キャンセルしました。(˙◁˙)パア') else : await message.channel.send('デフォルトは「n」なのでキャンセルしました。(˙◁˙)パア') else : await message.channel.send('管理者権限がない者は実行できません。') elif message.content.startswith == ('/'): if message.author.bot: return await message.channel.send('そのコマンドは存在しません') def new_func1(api): img = api.get_user return img def new_func(me): return me.screen_name client.run(TOKEN)

というプログラムです
これで/loginをすると

access_token: access_token_secret 認証が完了しました。 ようこそ Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\kusik\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "C:\Users\kusik\Desktop\新しいフォルダー (2)\import tweepy.py", line 119, in on_message await message.channel.send(embed=embed_message) File "C:\Users\kusik\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\abc.py", line 1065, in send data = await state.http.send_message(channel.id, content, tts=tts, embed=embed, File "C:\Users\kusik\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\http.py", line 254, in request raise HTTPException(r, data) discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In embed.thumbnail.url: Scheme "<bound method api.get_user of <tweepy.api.api object at 0x00000298c7681370>>" is not supported. Scheme must be one of ('http', 'https').

どうすれば解決できるでしょうか、

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問