Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Guild Bans #279

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
13 changes: 7 additions & 6 deletions lib/discordrb/api/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,18 @@ def bans(token, server_id, limit = nil, before = nil, after = nil)
)
end

# Ban a user from a server and delete their messages from the last message_days days
# Ban a user from a server and delete their messages from seconds.
# https://discord.com/developers/docs/resources/guild#create-guild-ban
def ban_user(token, server_id, user_id, message_days, reason = nil)
reason = URI.encode_www_form_component(reason) if reason
def ban_user(token, server_id, user_id, message_seconds, reason = nil)
Discordrb::API.request(
:guilds_sid_bans_uid,
server_id,
:put,
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete_message_days=#{message_days}&reason=#{reason}",
nil,
Authorization: token
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}",
{ delete_message_seconds: message_seconds }.to_json,
Authorization: token,
content_type: :json,
'X-Audit-Log-Reason': reason
)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/discordrb/data/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ def server_unmute
end

# Bans this member from the server.
# @param message_days [Integer] How many days worth of messages sent by the member should be deleted.
# @param message_seconds [Integer] How many seconds worth of messages sent by the member should be deleted.
# @param reason [String] The reason this member is being banned.
def ban(message_days = 0, reason: nil)
server.ban(@user, message_days, reason: reason)
def ban(message_seconds = 0, reason: nil)
server.ban(@user, message_seconds, reason: reason)
end

# Unbans this member from the server.
Expand Down
6 changes: 3 additions & 3 deletions lib/discordrb/data/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,10 @@ def bans(limit: nil, before_id: nil, after_id: nil)

# Bans a user from this server.
# @param user [User, String, Integer] The user to ban.
# @param message_days [Integer] How many days worth of messages sent by the user should be deleted.
# @param message_seconds [Integer] How many seconds of messages sent by the user should be deleted.
# @param reason [String] The reason the user is being banned.
def ban(user, message_days = 0, reason: nil)
API::Server.ban_user(@bot.token, @id, user.resolve_id, message_days, reason)
def ban(user, message_seconds = 0, reason: nil)
API::Server.ban_user(@bot.token, @id, user.resolve_id, message_seconds, reason)
end

# Unbans a previously banned user from this server.
Expand Down
Loading