質問編集履歴

1

startswithのエラーに関しても質問していましたが、無事解決しましたためそちらだけ削除しました。

2022/04/26 09:44

投稿

hurakiri
hurakiri

スコア16

test CHANGED
File without changes
test CHANGED
@@ -1,32 +1,4 @@
1
1
  discord.pyで、チャンネルに打ち込んだ内容を特定のユーザーのDMに送る機能をつけようとしているのですが、下記のようなエラーが起こってしまいます。
2
- ```python
3
- @bot.event
4
- async def on_message(message):
5
- def check(msg):
6
- return msg.author == message.author
7
-
8
- if message.content.startwith(".DMsend"):
9
- await message.channel.send("送信したい内容を入力")
10
-
11
- wait_message = await bot.wait_for("message", check=check)
12
-
13
- await message.channel.send("以下の内容を送信しました。")
14
-
15
- user = bot.get_user(DMuser)
16
- await user.send(wait_message.content)
17
- await message.channel.send(wait_message.content)
18
-
19
- ```
20
-
21
- ``` error
22
- Traceback (most recent call last):
23
- File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
24
- await coro(*args, **kwargs)
25
- File "パイソンファイルの場所.py", line 83, in on_message
26
- if message.content.startwith(".DMsend"):
27
- AttributeError: 'str' object has no attribute 'startwith'
28
- ```
29
- 仮にstartwithを使わずに行った場合こうなります。
30
2
 
31
3
  ```python
32
4
  @bot.event
@@ -56,8 +28,6 @@
56
28
  DMuserの変数を用意してその中に自分のユーザーIDを代入しています。
57
29
  以下のようにコピーしているのですが...
58
30
 
59
- startwithを使う場合の対処法('str' object has no attribute 'startwithの対処)と使わない場合の対処法('NoneType' object has no attribute 'send'の対処)を教えてほしいです。
60
-
61
31
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-04-26/6499faca-8ea1-4884-8072-d3497ad543cf.png)
62
32
 
63
33
  参考にしたものは以下です。