私は楽しみのために単純な不和ボットを書いています、そして私はそれが(例えば)特定のフレーズの後のメッセージから番号を取り、後でそれを使うことを望みます例えば特定のユーザーは「$ test6」とタイプしますそして私は私のボットに取りたいですその番号(6)と別の例では、同じチャネルに送信します。
この質問を作成してメッセージを分割した後に思いついたのですが、コンテンツは機能しますか?(ユーザーが数字以外の何かを書くことができることを数えません)
import discord
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("$test"):
stringOne = str(message.content)
stringTwo = "$test "
split = stringOne.partition(stringTwo)[2]
await message.channel.send("number/s from your message: " + split)
これは、コマンド引数を使用して実行できます。
@bot.command()
async def test(ctx, number = None):
if not number:
await ctx.send("Please enter a number, for example: `$test 5`")
else:
await ctx.send(f"Here's the number you gave me: {number}")
そして、いくつかの不和オブジェクトを使用した例:
@bot.command()
async def kick(ctx, member: discord.Member = None, *, reason = "Default reason"):
if not member:
await ctx.send("Please provide a member for me to kick!")
else:
await member.kick(reason=reason)
await ctx.send(f"Successfully kicked {member} for `{reason}`")
参照:
*
パラメータでの使用法commands.Command()
-コマンドを作成/ボットに登録するためのデコレータ。commands.Context
-これは常にコマンドの最初のパラメーターとして渡されます。Context.send()
-Context
から継承abc.Messageable
します。つまり、コマンドが実行されたチャネルにメッセージを送信できます。abc.Messageable
discord.Member
Member.kick()
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加