如何在 discord.py 中使用参数?
How do I use arguments in discord.py?
好的,我有这段代码,但是当我尝试使用 $announce 时,它不会回写 Hello。事实上,它没有响应我放在异步定义下的任何内容。怎么会?
我觉得我做的一切都正确,教程是我正在使用的重写和更新。
import discord
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit
prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = discord.Client()
@client.event
async def on_ready():
await client.change_presence(status = discord.Status.online, activity = discord.Game('have a nice day!'))
print("Bot is now online!")
@client.event
async def on_message(message):
if message.content.startswith("$hello"):
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(time())
if message.content.startswith("$dm"):
user = client.get_user(393921960817721355)
dm_channel = user.dm_channel
if (dm_channel==None):
dm_channel = await user.create_dm()
await dm_channel.send(f"""Hello!""")
if message.content.startswith("$servers"):
await message.channel.send(clattr.guilds)
if message.content.startswith("$help"):
await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
if message.content.startswith("$pinghelp"):
await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
@client.command()
async def announce(ctx, announcement):
await ctx.send(f"""Hello""")
TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)
我如下更改了您的代码,但请确保 discort.py 与此代码位于同一文件夹中。如果您遇到错误,请在您的条目中分享 error/warning,这会有所帮助。
from discord import *
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit
prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = Client()
@client.event
async def on_ready():
await client.change_presence(status = Status.online, activity = Game('have a nice day!'))
print("Bot is now online!")
@client.event
async def on_message(message):
if message.content.startswith("$hello"):
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(time())
if message.content.startswith("$dm"):
user = client.get_user(393921960817721355)
dm_channel = user.dm_channel
if (dm_channel==None):
dm_channel = await user.create_dm()
await dm_channel.send(f"""Hello!""")
if message.content.startswith("$servers"):
await message.channel.send(clattr.guilds)
if message.content.startswith("$help"):
await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
if message.content.startswith("$pinghelp"):
await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
@client.command()
async def announce(ctx, announcement):
await ctx.send(f"""Hello""")
TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)
好的,我有这段代码,但是当我尝试使用 $announce 时,它不会回写 Hello。事实上,它没有响应我放在异步定义下的任何内容。怎么会?
我觉得我做的一切都正确,教程是我正在使用的重写和更新。
import discord
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit
prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = discord.Client()
@client.event
async def on_ready():
await client.change_presence(status = discord.Status.online, activity = discord.Game('have a nice day!'))
print("Bot is now online!")
@client.event
async def on_message(message):
if message.content.startswith("$hello"):
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(time())
if message.content.startswith("$dm"):
user = client.get_user(393921960817721355)
dm_channel = user.dm_channel
if (dm_channel==None):
dm_channel = await user.create_dm()
await dm_channel.send(f"""Hello!""")
if message.content.startswith("$servers"):
await message.channel.send(clattr.guilds)
if message.content.startswith("$help"):
await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
if message.content.startswith("$pinghelp"):
await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
@client.command()
async def announce(ctx, announcement):
await ctx.send(f"""Hello""")
TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)
我如下更改了您的代码,但请确保 discort.py 与此代码位于同一文件夹中。如果您遇到错误,请在您的条目中分享 error/warning,这会有所帮助。
from discord import *
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit
prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = Client()
@client.event
async def on_ready():
await client.change_presence(status = Status.online, activity = Game('have a nice day!'))
print("Bot is now online!")
@client.event
async def on_message(message):
if message.content.startswith("$hello"):
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(f"""Hi""")
await message.channel.send(time())
if message.content.startswith("$dm"):
user = client.get_user(393921960817721355)
dm_channel = user.dm_channel
if (dm_channel==None):
dm_channel = await user.create_dm()
await dm_channel.send(f"""Hello!""")
if message.content.startswith("$servers"):
await message.channel.send(clattr.guilds)
if message.content.startswith("$help"):
await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
if message.content.startswith("$pinghelp"):
await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
@client.command()
async def announce(ctx, announcement):
await ctx.send(f"""Hello""")
TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)